WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to list posts from a specific category (4 posts)

  1. pacificdesignmatt
    Member
    Posted 4 years ago #

    can anybody tell me how i could achieve a sidebar like this http://redbarradio.com/ , i want to post podcasts and then list them in the sidebar on all pages.

    Thanks,
    Matt

  2. MichaelH
    Member
    Posted 4 years ago #

    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().
    ?>
  3. pacificdesignmatt
    Member
    Posted 4 years ago #

    thanks that works great :D

    Matt.

  4. lists
    Member
    Posted 4 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic