• This may be a simple answer but I have not found it in the codex and by searching. If I have a site with a blog that has the normal loop of posts displaying everything – but want a side bar showing the most recent posts to a specific category. For instance if I have a category that was politics only or entertainment only – and wanted to show the titles of the most recent 5 or 6 posts to that category – how could I do it on the main page? What snippet of code would I want?

    Thanks in advance.

Viewing 1 replies (of 1 total)
  • <?php
    //get 5 recent posts for categories 14 and 9
        $args=array(
          'category__in' => array(14,9),
          'showposts'=>5,
          'caller_get_posts'=>1
        );
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo '5 recent Posts';
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
          endwhile;
        } //if ($my_query)
      wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Display 5 most recent posts to specific category’ is closed to new replies.