List sub-categories for parent, posts for children
-
Here’s the behavior that I’m looking for:
When a user views a category (parent) that has children, this displays:
Parent Category Title Parent Category Description <a>Child Category Title</a> Child Category Description <a>Child Category Title</a> Child Category Description <a>Child Category Title</a> Child Category Description ..etc. When a category with NO child categories is viewed, then I want this to display: Category Title Category Description <a>Post Title</a> Post Description <a>Post Title</a> Post Description <a>Post Title</a> Post Description
Here’s the code that I have for listing Child Categories for a Parent:
$cat = get_query_var('cat'); $categories=get_categories('child_of='.$cat); if ($categories) { foreach($categories as $category) { echo '<h2><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </h2> '; echo '<p> Description:'. $category->description . '</p>'; } }
but then when I go to a category with no sub-categories, it is blank, no posts. Any ideas on how to pull those back in?
THANKS!
[ Please do not bump, that’s not permitted here. ]
- The topic ‘List sub-categories for parent, posts for children’ is closed to new replies.