WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Thord Daniel Hedengren
    Member
    Posted 8 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
    Member
    Posted 8 years ago #

    Have you tried the customisable post listings plugin?

  3. Thord Daniel Hedengren
    Member
    Posted 8 years ago #

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

  4. Thord Daniel Hedengren
    Member
    Posted 8 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:

    http://www.coffee2code.com/archives/2004/08/27/plugin-customizable-post-listings/#comment-5461

  5. moshu
    Member
    Posted 8 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 Daniel Hedengren
    Member
    Posted 8 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
    Member
    Posted 8 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.... :/

    spencerp

  8. Kafkaesqui

    Posted 8 years ago #

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

    <ul><li><h2>Recently</h2>
    <ul class="recent">
    <?php
    $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; ?>
    </ul>
    </li></ul>

    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():

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

  9. Thord Daniel Hedengren
    Member
    Posted 8 years ago #

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

  10. aylia
    Member
    Posted 8 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