我的 WordPress 页面中显示了一个类别列表。目前它显示所有带有链接的类别名称。我也想显示帖子号码。表示如果类别 A 有 10 个帖子,它将显示在其名称旁边。
这是我当前的代码片段:
<ul class="cat-list">
<?php
$args=array(
'orderby' => 'name',
'order' => 'ASC'
)
?>
<?php
foreach (get_categories( $args ) as $cat) : ?>
<li>
<div class="post-title">
<h5><a href="<?php echo get_category_link($cat->term_id); ?>"><i class="fa fa-arrow-circle-right"></i> <?php echo $cat->cat_name; ?></a></h5>
</div>
</li>
<?php endforeach; ?>
</ul>
这就是我想做的事情:
最佳答案
当你循环获取“category_count”时,尝试这样的事情
<?php
$cat = get_the_category();
$cat = $cat[0];?>
echo $cat->category_count;
?>
此链接可能对您有帮助 https://wordpress.org/support/topic/display-the-posts-count-in-the-selected-category
关于php - 如何在 WordPress 中的类别名称旁边显示帖子编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30266182/