How to display multiple parentage in a category template

By the Web Warlock, Friday, 14/May/2010 9:44

To display all the posts that belong to a category and include multiple parentage (that is, display also the posts that belong to a meta-children term), we'll have to redo a bit the query of The Loop. What we'll do is retrieve all the children of the queried term, and use the list of ids for the category__in parameter of the query. So, just before The Loop starts (normally it's with if( have_posts() ): ), just add the following:

$posts = query_posts( array(
     'category__in' => get_all_meta_children( (int)get_query_var( 'cat' ) )
     , 'paged' => get_query_var( 'paged' )
) );

You can also set some parameters to the get_all_meta_children function, such as the depth of children to display (that is, the "generations" of children and grandsons &c to include); and, actually, you don't need to pass the query var cat parameter; it's just there for clarity.

No Comments »

No comments yet.

RSS feed for comments on this post.

Leave a comment