Skip to:

“alphabetical” ordering of hot tags

  • Would there be a way to change the order tags are displayed?

    I can’t find where it is sorting them.

    The tags when they are all English, are ordered alphabetically, but tags in Japanese come up in a strange order, probably the ascending order of characters stored in db like %82….

    (It is showing “other” at the start, which looks pretty silly.)

    If I can order by the database’s id field or something, it’s great…

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

  • _ck_


    It uses the action

    do_action_ref_array( 'sort_tag_heat_map', array(&$counts) );

    which looks like

    function bb_sort_tag_heat_map( &$tag_counts ) {
    uksort($tag_counts, 'strnatcasecmp');

    So it was designed to be replaced fortunately.

    First to have to unhook the existing action in your plugin:

    remove_filter('sort_tag_heat_map', 'bb_sort_tag_heat_map');

    Then put in your replacement

    add_filter('sort_tag_heat_map', 'my_sort_tag_heat_map');

    function my_sort_tag_heat_map( &$tag_counts ) {
    // put your replacement code here

    According to this, it’s supposed to support your locale, but there is a bug:

    Thanks for reply, ck.

    I didn’t know how to make plugins..

    So, anywhere that say

    apply_filter('___', '___');

    can be replaced?

    Now.. about original question:

    $tag_counts is

    • key: raw_tag
    • value: how many times topics are tagged with this tag

    Googling a bit more made me realize, there’re problems associated with ordering Japanese words/strings as there’re 2 types of letters and chinese character used.

    strnatcasecmp() seem to put things in order of

    1. hiragana in ascending
    2. katakana in ascending
    3. chinese characters in encoding#

    ssetlocale(LC_COLLATE, "jp", "jpn");
    ksort($tag_counts, SORT_LOCALE_STRING);

    shows exactly the same result.

    It seems pretty impossible (for me) to order them.

    I will flip it to descending, with krsort(); just so the tag “other” won’t come to start.



    bbPress uses the same concept as WordPress with add_filter and add_action so there are many guides out there as to how it works.

    Essentially it’s a “hook” that allows you to intercept the process or results. The first part of the add_action/add_filter is the process name or trigger, the second part the the name of the function you want to process at that moment.

    If there are existing filters/actions in place you can unhook them with remove_action or remove_filter.

    Thank you.

    I will look for those guides. (And re-do all the “hack”s if possible..)

    Should’ve thought about looking for WordPress guides instead of bbPress ones.



    Any guide that is for WordPress plugins should work for bbPress, it’s just that bbPress’s “hooks” (do_action, do_filter) will be named differently.

    bbPress is unfortunately too young to have decent documentation yet. WordPress itself didn’t really “take off” until 2.0 beta came out.

    This is essentially the plugin framework you need:

    Plugin Name: My Tag Sort
    remove_filter('sort_tag_heat_map', 'bb_sort_tag_heat_map');
    add_filter('sort_tag_heat_map', 'my_sort_tag_heat_map');

    function my_sort_tag_heat_map( &$tag_counts ) {
    // put your replacement code here

    Save it as my-tag-sort.php, put it into the bbpress/my-plugins folder, activate and you’re in business (well after you figure out the sort method).

    Typically you’d have to do a return $tag_counts; at the end of a filter but that & on the &$tag_counts means it’s “passed by refererence” which is a fancy way of using the original array directly without making a copy, so the original is changed at the source when you modify it. It’s a much faster way to move large amounts of info around.



    By the way, I have no idea how many characters there are in the alphabets you are trying to order, but if the number is not too crazy, in theory you could make a string of the alphabetical character order you want (single characters in a row) and then write your own sort routine to sort based on the example string you give it. The sort won’t be as fast as the built in ones in PHP but you’ll get the order you want.

    If the problem is just different languages getting mixed up, what you could do is break up the tag array into multiple arrays of the different languages sets, sort each language, and then build a resulting array of appending one language array to the other, instead of sorting/mixing them together.

    I do some fancy things with the hot tag list too and what I do is cache the final result to disk instead of generating it each and every time. When a new tag is added I just delete the cache and have it regenerate. Depending on how slow your sort is, you could use that approach, but first see if you can get the sort working.

    Thanks ck,

    hiragana/katakana are ok, only 50+ letters each, only one pronounciation each but…

    the number of Chinese characters used is “crazy”, as well as one character having several ways of pronouncing, so that’s a real problem… I wonder how MSWord etc does the sorting that actually works.

    Though the way I hacked to make tags only selectable out of list (only mods/admins/etc can add new one to list. Bit dodgey hack..) leaves a possibility of caching it in order maybe…

    For now, I made a plugin, thanks to your instruction, to sort it descending order, so it is sorted in Chinese character -> Katakana -> Hiragana

    I was actually very happy I could make a plugin, instead of hacking the function, so, thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar