CountPost WordPress自定义分类

时间:2016-10-17 作者:Ji\'t

向类别列表中添加“count posts”的最简单方法是什么,如下所示?

<?php
if($categories){
    foreach($categories as $category) {
        $output .= \'<li><a href="\'.get_category_link( $category->term_id ) . \'" title="\' . esc_attr( sprintf( esc_html__( \'View all posts in %s\',\'themename\' ), $category->name ) ) . \'">\' . $category->name . \'</a></li>\' . $separator;
    }
    echo trim($output, $separator);
}

1 个回复
最合适的回答,由SO网友:Robbert 整理而成

我不知道你的确切意思,但我想你需要这样的东西?

$categories = get_terms( array( \'taxonomy\' => \'category\' ) );
if ( $categories ) { 
   $output = \'\';
   foreach( $categories as $category ) {
      $output .= \'<li title="\' . __( \'View all\', \'themename\' ) . \' \' . $category->count . \' \' . __( \'posts in\', \'themename\' ) . \' \' . $category->name . \'">\' . $category->name . \' \' . $separator . \'</li>\';
   }
   echo trim( $output, $separator );
}

相关推荐

显示KK星级评级插件的“ratingValue”和“ratingCount”值​

我想显示“ratingValue”和“ratingCount”值​​由生成KK Star Ratings plugin (Github).我制作了一个JSON-LD软件应用程序,下面是我在函数中使用的代码。php:add_action(\'wp_head\', \'add_jsonld_head\', 1); function add_jsonld_head() { if ( is_single() ) { ?> <scr