Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Editing Forum heat map (tag cloud) settings


Boone Gorges
Keymaster

@boonebgorges

snark – You don’t need to hack the core files. (Though, admittedly, this would be a lot easier if the tag cloud were filterable before it was converted into HTML. The method I used is clunky at best.) The following two functions in functions.php should rearrange all tag clouds to be in alphabetical order:

function bbg_compare_alphabetical($a, $b) {
return strCmp($a['name'], $b['name']);
}

function bbg_alphabetical_tag_cloud_filter( $a, $b ) {
$tags = explode( "\\n", $a );
$tags_new = array();
foreach( $tags as $key => $tag ) {
$tag_split = explode( '</a>', $tag );
$cut = strrpos( $tag_split[0], '>' );
$tag_name = substr( $tag_split[0], $cut + 1 );
$tag_new = array( 'name' => $tag_name, 'html' => $tag );
$tags_new[] = $tag_new;
}

usort( $tags_new, "bbg_compare_alphabetical" );

$tags_sorted = array();
foreach( $tags_new as $tag ) {
$tags_sorted[] = $tag['html'];
}
$tags_sorted = implode( "\\n", $tags_sorted );

return $tags_sorted;
}
add_filter( 'tag_heat_map', 'bbg_alphabetical_tag_cloud_filter', 10, 1 );

Skip to toolbar