• New switcher from MT. Would like to have a page that lists all categories with a permalink to associated posts underneath each one. Having a hard time. The wp_get_archives function can’t handle categories. Should I be using get_posts instead? Is there a forum thread I’ve missed. New to PHP, so the simpler the better. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • <?php
    //for each category, show 3 posts
    $cat_args=array(
      'orderby' => 'name',
      'order' => 'ASC'
       );
    $categories=get_categories($cat_args);
      foreach($categories as $category) {
        $args=array(
          'showposts' => 3,
          'category__in' => array($category->term_id),
          'caller_get_posts'=>1
        );
        $posts=get_posts($args);
          if ($posts) {
            echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
            foreach($posts as $post) {
              setup_postdata($post); ?>
              <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
              <?php
            } // foreach($posts
          } // if ($posts
        } // foreach($categories
    ?>
    Thread Starter jrygielski

    (@jrygielski)

    Didn’t seem to work. I’m messing it up no doubt. Which template should this go into? Anything special I need to do with the loop? Sorry, newb..

    For examle, this works just fine for me with the WordPress Default theme’s wp-content/themes/default/index.php and placed just before:

    <?php if (have_posts()) : ?>

    Thread Starter jrygielski

    (@jrygielski)

    Ah! It worked. I’m learning this while trying to develop a custom theme. Can I adjust the showposts value to show all posts in the category?

    i want to show latest post with content of each category.

    what changes should i make in above code to work.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show all categories and their posts?’ is closed to new replies.