admin管理员组文章数量:1316839
I've been stuck on this for a little while now, and have tried multiple ways to achieve this with no luck. I've been looking for two ways to display the total posts found on a specific, and non-specific, category page(s). To further specify, the first I'd like to show the total number of posts for a specific (parent) category page. The second, show the total number of posts for a single category (without specifying it's ID, name or slug).
For example, I have an index page dedicated to my parent category, "Blog Entries", which has several subcategories (Fashion, Beauty, Lifestyle, Travel, etc) that are all displayed on this page. In the title of this page I want it to display the total number of posts Blog Entries has including it's sub categories like: Browsing all Blog Entries. 36 Posts Found. I have tried something like this:
<?php
$categories = get_category( get_category_by_slug( 'blog-entries' )->term_id );
foreach($categories as $category) {
$total += $category->count;
} echo $total . ' posts found.';
?>
However, this displays the total number as 0 because it's only specifying the category 'blog entries' and is not including in it's subcategories. I'm not sure how to get it to include it's subcategories.
For the second example, in short I have a general category/archive page that I would like to have a same thing done in the title - Browsing all [category] Entries. 6 Posts Found. I have yet to find a solution that does not specify the category. Is this possible? I don't really want to have to make specific pages for all my categories.
Thanks in advance!
本文标签: wp queryShow Post Count of a Category
版权声明:本文标题:wp query - Show Post Count of a Category 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742014557a2413524.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论