Skip to:
Content
Pages
Categories
Search
Top
Bottom

Editing Forum heat map (tag cloud) settings


  • snark
    Participant

    @snark

    I am running a fresh installation of BP 1.2-RC3(trunk 2714) for WP 2.9.1 single user. I am looking for a a custom function, if possible, to add to my child directory functions.php file where I can change the forum heat map (tag cloud) settings and avoid editing a core file.

    This the following function in bp-forums/bp-forums-templatetags.php that controls the tag cloud settings:

    function bp_forums_tag_heat_map( $args = ” ) {

    $defaults = array(

    ‘smallest’ => ’10’,

    ‘largest’ => ’42’,

    ‘sizing’ => ‘px’,

    ‘limit’ => ’50’

    );

    $r = wp_parse_args( $args, $defaults );

    extract( $r, EXTR_SKIP );

    bb_tag_heat_map( $smallest, $largest, $sizing, $limit );

    }

    Is it possible to make a custom function that would override this one? Any help is most appreciated. Thanks.

Viewing 17 replies - 1 through 17 (of 17 total)

  • snark
    Participant

    @snark

    Any ideas on a function for this?


    snark
    Participant

    @snark

    Anyone?

    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>


    snark
    Participant

    @snark

    Perfect, @DJPaul, that did the trick. Thanks. I’m starting to get the hang of this.


    snark
    Participant

    @snark

    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?


    snark
    Participant

    @snark

    @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.


    snark
    Participant

    @snark

    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.


    Boone Gorges
    Keymaster

    @boonebgorges

    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().


    snark
    Participant

    @snark

    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?


    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 );


    snark
    Participant

    @snark

    @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?


    snark
    Participant

    @snark

    Just bumping this, hoping @boonebgorges or someone else who can tweak his functions so they work without an error. Thanks.


    Boone Gorges
    Keymaster

    @boonebgorges

    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 ).


    snark
    Participant

    @snark

    @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!


    snark
    Participant

    @snark

    @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.


    snark
    Participant

    @snark

    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.


    Vernon Fowler
    Participant

    @vernonfowler

    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; }`

Viewing 17 replies - 1 through 17 (of 17 total)
  • The topic ‘Editing Forum heat map (tag cloud) settings’ is closed to new replies.
Skip to toolbar