Display posts from several categories (get_posts?) – how?
-
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?
-
Have you tried the customisable post listings plugin?
No. I would rather use a function built into WP, but maybe that’s not possible?
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
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…
“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.
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
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():
Thanks Kafkaesqui, I’ll try that tomorrow, but it sure looks like what I’m after! 🙂
this looks like what I’m looking for too..
can you use it more than once on a page?
- The topic ‘Display posts from several categories (get_posts?) – how?’ is closed to new replies.