WordPress.org

Ready to get started?Download WordPress

Forums

Show posts from a category on the sidebar (7 posts)

  1. tariqbamadhaj
    Member
    Posted 6 years ago #

    I would like to show posts from a particular category only. I am using Tabber and I would like to show the last 5 posts for the review category?

    What tag should I use? I can't seem to find it.

    Thank you.

  2. tariqbamadhaj
    Member
    Posted 6 years ago #

    Anyone?

  3. Justin Tadlock
    Member
    Posted 6 years ago #

    <?php
    query_posts('cat=4&showposts=5'); // By category ID
    if(have_posts()) :
    	while(have_posts()) :
    		the_post;
    		// Post stuff here
    	endwhile;
    endif;
    ?>

    Or, change the query to:

    query_posts('category_name=Reviews&showposts=5');

    http://codex.wordpress.org/Template_Tags/query_posts

  4. sabinou
    Member
    Posted 6 years ago #

    Chance made me open the perfect link for you a few minutes ago, and I didn't think of closing the tab :

    http://herselfswebtools.com/2007/10/how-to-list-all-posts-from-a-specific-category-in-your-sidebar-in-wordpress.html

  5. Ivovic
    Member
    Posted 6 years ago #

    I prefer get_posts() for this, because its a bit lighter on queries.

  6. Justin Tadlock
    Member
    Posted 6 years ago #

    Yes, get_posts() would probably be better for this.
    http://codex.wordpress.org/Template_Tags/get_posts

  7. Ivovic
    Member
    Posted 6 years ago #

    I'd only recently discovered that little gem myself actually... when I converted all my sidebar extractions to get_posts, I shaved 30 queries off my main page.

    Not insignificant...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.