Wordpress Tip: get current category with query-posts

Better than unique category templates.

If you’re theme developing, especially using a theming framework like Carrington (in my case), you might want to create a generic query to grab posts based on a category, without creating creating unique template files for reach category. Here’s some code I used. Simple, but you won’t find an exact example in the Codex.


foreach(get_the_category() as $category)
{
  $cat = $category->cat_ID;
}
query_posts('orderby=menu_order&cat=' . $cat . '&order=ASC');

Category:

Author: rosschapman

Tags:

Created on: October 1st, 2009

leave a comment

Back to article list