Viewing 3 replies - 1 through 3 (of 3 total)
  • In a sidebar.php or a PHP code widget you could use something like:

    <?php
        $args=array(
          'cat' => 5,
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'List of Posts in category 5';
          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;
        }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    Thread Starter pacificdesignmatt

    (@pacificdesignmatt)

    thanks that works great ??

    Matt.

    This is great code. Is there a way to limit the listing to the current category and not the sub-cats? It seems to list all posts down the tree.

    maybe using filter with in_category() ro something like that?

    thanks

    Shawm

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to list posts from a specific category’ is closed to new replies.