admin管理员组文章数量:1391951
In WordPress, how do I get the number of posts next to <?php single_cat_title(''); ?>
in the category.php file?
<h1><?php single_cat_title(''); ?> (<?php ????code to count number of posts in the category shown?>?? ?>)</h1>
In WordPress, how do I get the number of posts next to <?php single_cat_title(''); ?>
in the category.php file?
<h1><?php single_cat_title(''); ?> (<?php ????code to count number of posts in the category shown?>?? ?>)</h1>
Share
Improve this question
asked Feb 18, 2020 at 14:49
Glen Charles RowellGlen Charles Rowell
516 bronze badges
2 Answers
Reset to default 1I figured out how to do it.
This code shows the number of posts on a page after clicking on a category in WordPress. Even if the post has lots of categories.
<?php $category = get_queried_object(); echo $category->count; ?>
I used this code as the code was in the category.php file and not part of the regular loop.
I hope this code helps anyone else if they are having the same type of problem.
You can use the function get_category() to get the category object and then just simply echo the $count property value.
$cat_count = get_category( 'ID OR ROW OBJECT' );
echo $cat_count->count;
If you also want to get the category object or ID before that then use this code:
$categories = get_the_category();
$category_id = $categories[0]->cat_ID;
本文标签:
版权声明:本文标题:categories - In WordPress, how do I get the number of posts next to single_cat_title(''); in the category.php fi 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744738555a2622474.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论