I'm looking for a solution to display a tag list that shows how many times the tag has been used in posts as well as link to a list of results. I found a php code snippet you posted on the Wordpress forum here http://wordpress.org/support/topic/how-to-display-the-number-of-posts-under-each-tag?replies=30
<?php
// Select all the post tag IDs
$the_tags = $wpdb->get_col("SELECT term_id
FROM $wpdb->term_taxonomy WHERE taxonomy = 'post_tag'" );
// Loop over each ID, and grab associated data
foreach($the_tags as $tag_id) {
// Get information on the post tag
$post_tag = get_term( $tag_id, 'post_tag' );
// Print the tag name and count (how many posts have this tag)
echo $post_tag->name.' ( '.$post_tag->count.' )<br />';
// Unset the data when it's not needed
unset($post_tag);
}
?>
It's almost perfect for what I need however I'd like to wrap it in a list item and link along with a span over the number. I took the echo line and did this:
echo '<li><a href=\"<?php echo get_tag_link($tag_id); ?>\">'.$post_tag->name.' </a><span>('.$post_tag->count.')</span></li> ';
I gave it my best guess but know it's not right. I know very little about PHP and am not sure if it's just a case of concatenating it correctly or if the get_tag_links part is even correct. Would you be able to help me out? Thanks so much for your time.
echo '<li><a href="'. get_tag_link($tag_id).'">'.$post_tag->name.' </a><span>('.$post_tag->count.')</span></li> ';