Something like this will do it.
$tags = get_tags(array(
'orderby' => 'count',
'order' => 'DESC',
'number' => 30,
) );
foreach ($tags as $tag) {
echo $tag->name . '(' . $tag->count . ')';
}
Thanks. I will give it a try for sure and let you know.
well it worked…kinda. i lost the linking when it displayed. now i know how to bring it back with some hard-coding but i wondered if there was an easier way.
Well, you didn’t say that you wanted it linked. You have to be specific about these sort of things.
$tags = get_tags(array(
'orderby' => 'count',
'order' => 'DESC',
'number' => 30,
) );
foreach ($tags as $tag) {
echo '<a href="' . get_tag_link($tag->term_id) . '" rel="tag">' . $tag->name . '</a>(' . $tag->count . ')<br />';
}
That will display them one per line. You just have to modify the echo line if you want them displayed differently.
755565
Hi Otto42,
Thank you for this code. It mostly serves my needs, but I’m hoping there’s a way to format the display of the tags in a list, so that the bullets in the theme I’m using are displayed.
Here’s a screen capture of how I incorporated your code into the PHP Code Widget:
http://www.dotglu-review.com/public/screen_captures/tag_list_code.gif
Here’s a screen capture of the displayed tag list:
http://www.dotglu-review.com/public/screen_captures/tag_list_display.gif
You’ll notice the tag list doesn’t include the proper bulleted formatting.
Any help you can offer is very much appreciated.
Thank you!
S
Otto42, the code block you provided above is very helpful. I’ve tried wrapping your echoed statement in LI and having a conditional class inside the LI but I just can’t get this to work.
Can you tell us how to incorporate a conditional class such as below into your code block. Sorry if this is not as clear as it could be – I’m not a programmer.
<li <?php if(is_tag('TheCurrentTag')){echo 'class="current-cat"';}?>>
Ott042,
This is great.
Is there a way to have the numbers display in () as I have it setup? Currently the numbers are running into the tag name.
You can see the action here:
http://www.inform-ventures.com/blog/
This is the code I am using from above:
<?php $tags = get_tags(array(
'orderby' => 'count',
'order' => 'DESC',
'number' => 30,
) );
foreach ($tags as $tag) {
echo '<li><a href="' . get_tag_link($tag->term_id) . '" rel="tag">' . $tag->name . $tag->count . '</a></li>';}; ?>
Nevermind. Figured it out.
Otto,
Thanks a bunch for this code; it really helped me out. π
Eric
I’m wondering if there’s a way to omit certain tags, or better yet, only include tags that I specify? Similar to the wp_list_categories options.
sewmyheadon: you can just add another line, like this and add the tags you wish to include…
'include' => '1,2,3,4,5,6'
Otto42: If you get the chance, would you please take a look at my question above. Thanks.
tnerb, Thanks a bunch! Worked like a charm! π
inform could you tell me how you put the ()around tag count.
thanks.
@ zbrix
See code below:
'(' . $tag->count . ')'
In what file does this code go in?