向类别列表中添加“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);
}
最合适的回答,由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 );
}