Get number of posts from all of a parent category's children
-
I found a few articles about getting the number of posts from a category, and I’ve got that working fine in child categories.
What I’m having a problem with getting a number of posts from a parent category, for all it’s children.
PARENT CATEGORY: Animals for Adoption (number of posts 0)
Child Categories: Cats for Adoption (5 posts), Dogs for Adoption (6 posts).
What I want is to show how many posts are in allllll the child categories of “Animals for Adoption” category (page), if it is possible, with out making these people double categorize an animal’s listing (because they barely grasp how to use the site as it is ?? )
Right now I’m using this and like I said, it is showing correctly on the child category pages. It is not printing anything on the parent page, because technically none of the posts have actually been assigned to the parent’s category, just one of the children.
$cat = get_query_var('cat'); $categories=get_categories('include='.$cat); if ($categories) { foreach($categories as $category) { echo $category->count . ' Listings Total'; } }
- The topic ‘Get number of posts from all of a parent category's children’ is closed to new replies.