Display posts from several categories (get_posts?) - how? (10 posts)

  1. Thord D. Hedengren
    Posted 9 years ago #

    I want to display a list of recent posts i several categories. Previously I've used get_posts but it seems you can only limit it to all or just one category.

    Any suggestions?

  2. Usayd
    Posted 9 years ago #

    Have you tried the customisable post listings plugin?

  3. Thord D. Hedengren
    Posted 9 years ago #

    No. I would rather use a function built into WP, but maybe that's not possible?

  4. Thord D. Hedengren
    Posted 9 years ago #

    I've looked into the plugin a bit and it does look nice (since there's no WP way to deal with this?) but this is rather alarming:


  5. moshu
    Posted 9 years ago #

    Actually, if you read that comment's author's blog - you could realize it is about the "most recently commented" posts that caused the problem. I've never heard about any problem with the simple posts listings...

  6. Thord D. Hedengren
    Posted 9 years ago #

    "If there's one flaw, there's bound to be others?"

    But you're right, probably just when it needs to check every post and there's no need to do that when you're just retrieving X posts from the Y and Z category.

  7. spencerp
    Posted 9 years ago #

    How about this one:

    Plugin URI: http://blog.jodies.de/archiv/2004/11/13/recent-comments/

    I know it might not be to your liking, but that's what I use on my blog. When ever someone posts on my blog, no matter what catagory...it's posted on main index page. Click on my name for demo...unless you're after something more indepth.... :/


  8. Kafkaesqui

    Posted 9 years ago #

    Built-in method for displaying recent posts in selected categories:

    <ul class="recent">
    $recent = new WP_Query("cat=1, 10, 20&showposts=10");
    while($recent->have_posts()) : $recent->the_post();
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>

    Looking at the WP_Query parameters, 'cat' is the category ID for the category to display; for more than one category delimit them with a comma. And 'showposts' is the number of posts to list.

    Note the WP_Query() class takes the same parameters as query_posts():


  9. Thord D. Hedengren
    Posted 9 years ago #

    Thanks Kafkaesqui, I'll try that tomorrow, but it sure looks like what I'm after! :)

  10. aylia
    Posted 9 years ago #

    this looks like what I'm looking for too..

    can you use it more than once on a page?

Topic Closed

This topic has been closed to new replies.

About this Topic