Wordpress loop: Grouping by category?
I need to get all posts via the wordpress loop开发者_JS百科 but i need them to be grouped by category and cronological within each category. Anyone know how I should go about this?
Thanks!
You can use a new WP query to grab posts by category and display them chronologically from newest to oldest or otherwise. This works in the standard WP loop in a page template (or in the post/page editor if php execution is enabled), and can be used any number of times in the loop without conflicting with other queries. Change "mycategory" to your own category and change showposts=1 to the number of posts to show, or -1 to show all.
<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a><br /><?php the_content(); ?><?php endwhile; ?>
Function Reference/WP Query « WordPress Codex
Look at this If this doesn't sort chronological in each, then you'll just need to add the "post_date DESC" to the appropriate query.
精彩评论