views:

156

answers:

2

Hello,

I need to get all posts via the wordpress loop but i need them to be grouped by category and cronological within each category. Anyone know how I should go about this?

Thanks!

A: 

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.

easement
+2  A: 

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

songdogtech
Thanks for posting the class up! But is there a way to write custom queries with it?
This isn't a class; it's a group of functions and it will group your posts by category and date. What exactly do you want to query for? Number of posts? Sort order? If you're talking about a Mysql query, that's a different question than your current question.
songdogtech
Perhaps I worded it incorrectly. Sorry about that. I want like to be able to get all posts from wordpress and have a result set like so: posts grouped by category and the posts chronological within each category.
My answer does that; run one of those new query blocks for each category, change showposts=1 to -1 to show all posts. What exactly do you mean by a custom query? In MySQL? That's a different question.
songdogtech