Return to Snippet

Revision: 32132
at September 19, 2010 03:29 by daipratt


Initial Code
<?php
function top_tags() {
	$tags = get_tags();

	if (empty($tags))
		return;

	$counts = $tag_links = array();
	foreach ( (array) $tags as $tag ) {
		$counts[$tag->name] = $tag->count;
		$tag_links[$tag->name] = get_tag_link( $tag->term_id );
	}

	asort($counts);
	$counts = array_reverse( $counts, true );

	$i = 0;
	foreach ( $counts as $tag => $count ) {
		$i++;
		$tag_link = clean_url($tag_links[$tag]);
		$tag = str_replace(' ', '&nbsp;', wp_specialchars( $tag ));
		if($i < 11){
			print "<li><a href=\"$tag_link\">$tag ($count)</a></li>";
		}
	}
}
?>
<h4>Top tags</h4>
<ul>
<?php
top_tags();
?>
</ul>

Initial URL
http://daipratt.co.uk/tag/wordpress/

Initial Description
Show the top tags by usage.

Initial Title
Wordpress - show top 10 tags by usage

Initial Tags
wordpress

Initial Language
PHP