admin管理员组

文章数量:1323342

I thought this would have displayed the post counts right next to the clickable links

wp_tag_cloud( 
array( 'taxonomy' => $taxonomy, 
'format' => 'list', 
'smallest' => 12,  
'largest' => 12, 
'number' => 10000 , 
'separator' => '<li>' ,  
'topic_count_text_callback'=> 'default_topic_count_text' ) 
 );

but, it ends up displaying this;

item 1 
item 2 
item 3 

What's the trick to make it display something like this?

item 1 (100)
item 2 ( 90 )
item 3 (15 )

I tried the following codex code, but that caused no visible change.

wp_tag_cloud( array( 'topic_count_text_callback' => 'my_tag_text_callback' ) ); 

function my_tag_text_callback( $count ) {
 return sprintf( _n('%s picture', '%s pictures', $count), number_format_i18n( $count ) );
}

I thought this would have displayed the post counts right next to the clickable links

wp_tag_cloud( 
array( 'taxonomy' => $taxonomy, 
'format' => 'list', 
'smallest' => 12,  
'largest' => 12, 
'number' => 10000 , 
'separator' => '<li>' ,  
'topic_count_text_callback'=> 'default_topic_count_text' ) 
 );

but, it ends up displaying this;

item 1 
item 2 
item 3 

What's the trick to make it display something like this?

item 1 (100)
item 2 ( 90 )
item 3 (15 )

I tried the following codex code, but that caused no visible change.

wp_tag_cloud( array( 'topic_count_text_callback' => 'my_tag_text_callback' ) ); 

function my_tag_text_callback( $count ) {
 return sprintf( _n('%s picture', '%s pictures', $count), number_format_i18n( $count ) );
}
Share Improve this question asked Jun 11, 2012 at 10:00 Average JoeAverage Joe 1,8894 gold badges24 silver badges41 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 1

You'll have to use the get_terms function to build your own list if you want the count in there.

If we read the details of topic_count_text_callback we can see why it may appear to not be working:

topic_count_text_callback

(string) (optional) The function, which, given the count of the posts with that tag, returns a text for the tooltip of the tag link. Default: default_topic_count_text

this function sets the link's title attribute text, it doesn't show the count with the term directly in the text. If you hover over the links you'll see the text pop-up in a tooltip next to your cursor.

$tax_list = wp_list_categories( array( 'taxonomy' => 'YOUR-CUSTOM-TAXONOMY', 'orderby' => 'name', 'show_count' => 1, 'pad_counts' => 0, 'hierarchical' => 1, 'echo' => 0 ) );

Echo $tax_list that to the browser and you're done.

I'm a bit late. You can use "show_count" => 1 as args in wp_tag_cloud and you will see your term count against its name. :-) Enjoy

本文标签: tagsDisplaying the post count of all custom taxonomy terms in a list format