Any ideas on a function for this?
Yeah, make a function, put it in functions.php like you’ve said. Then in your child theme’s sidebar.php file, change line 64 from something like this:
<div id=”tag-text”><?php bp_forums_tag_heat_map(); ?></div>
to
<div id=”tag-text”><?php my_new_function(); ?></div>
Perfect, @DJPaul, that did the trick. Thanks. I’m starting to get the hang of this.
Now all I have to do it figure out how to change the default display of tags on the page. I’ve created a tag cloud display for the Forum tags at the top of the forum directory page, and used a custom function like @DJPaul suggested above to change the sizing and limits. But I can’t figure out how or where to change the sort order of the display.
By default the display is showing the tags with the most hits first, and then all the rest in no particular order. I would like to display all the tags in alphabetical order. But how?
@DJPaul — I tried tweaking the function you gave me — it didn’t create an error, but it didn’t work either. Here’s what I tried:
/* Customized heat map (tag cloud) function */
function bp_forums_tag_heat_map_x( $args = '' ) {
$defaults = array(
'smallest' => '10',
'largest' => '18',
'sizing' => 'px',
'limit' => '100',
'orderby' => 'name',
'order' => 'ASC'
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
bb_tag_heat_map( $smallest, $largest, $sizing, $limit, $orderby, $order );
}
I tried adding ‘orderby’ and ‘order’ arguments, but it didn’t work. Does anybody know how to tweak this function I’m using in my child theme to change the display order of the Forum tag cloud? By default it orders by most occurrences first and then in order of creation, so all new tags don’t even show up. I’d like to include tags by most occurrences, but then order them alphabetically. Thanks.
Any ideas on this? It seems like it should be an easy tweak to change the Forum tag cloud sort order that a lot of people might want to do, but I can’t find an info on it anywhere.
You’ll have to dig pretty deep into the bbPress code to make this work right. bp_forums_tag_heat_map uses bb_tag_heat_map to create the cloud, and it doesn’t take order or order_by as an argument. bb_tag_heat_map then goes to bb_get_tag_heat_map. If you were going to make the reordering happen (without a lot of funny business) it might best happen at the level of bb_tag_heat_map (or a custom version of that function). The list of tags is created like this (see buddypress/bp-forums/bbpress/bb-includes/functions.bb-template.php):
$tags = bb_get_top_tags( array( 'number' => $limit ) );
which returns an array. You could then try using usort to sort by $tags[‘count’] before sending $tags to bb_get_tag_heat_map().
Thanks @boonegorges , but that’s beyond me, and I don’t want to hack up the core files. Any chance of adding a hook to BP or whatever it requires so that a simple(r) function added to the child theme functions.php file could adjust the sort method and order?
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 );
@boonebgorges — Your functions worked like a charm to achieve alphabetized forum tags, but they returned a warning error above the tags:
Warning: Missing argument 2 for bbg_alphabetical_tag_cloud_filter() in …/httpdocs/wp-content/themes/…/functions.php on line 163
Here is the line of code referenced by the warning:
function bbg_alphabetical_tag_cloud_filter( $a, $b ) {
Looks like “$b” needs some sort of argument?
Just bumping this, hoping @boonebgorges or someone else who can tweak his functions so they work without an error. Thanks.
Not sure why I included the $b in there in the first place. Try either removing it so you only have ( $a ) or changing it so that the arguments are ( $a, $b = false ).
@boonebgorges — removing the ‘$b’ didn’t work, but changing ( $a, $b ) to ( $a, $b = false ) in the second function did the trick. Thanks for your help!
@boonebgorges — One small issue I have noticed: the function separates capitalized and non-capitalized tags, putting all the capitalized tags first. I want all tags to be alphabetized together in one group, regardless of whether they are capitalized or not. Thanks.
Re-posting this here at the new BuddyPress.org community:
@boonebgorges — One small issue I have noticed: the function separates capitalized and non-capitalized tags, putting all the capitalized tags first. I want all tags to be alphabetized together in one group, regardless of whether they are capitalized or not. Thanks.
Thanks for these brilliant additions to forums. I’d been wondering for some time why tags weren’t appearing anywhere as I’d initially had the groups forum directory switched off. Now we have the opposite extreme using all the suggestions above – alpha sorted tag clouds for individual topics and for all groups forums appearing in all the right places. Thanks @snark and @boonebgorges – you’ve made my day.
Oh, by the way, since input of uppercase/lowercase tags doesn’t make any difference, you might consider use of CSS formatting like this:
`your_selector a { text-transform:lowercase; }`