Show BBpress Topic Tags from Inside WordPress

I’ve been hosting a forum at http://diylilcnc.org using WordPress and BBrpess integration, so that WordPress and BBpress share user accounts. This is great for the most part; one drawback is that while you can use some of the WordPress functions inside BBpress, you can’t go the other way and call BBpress functions from inside WordPress.
For example, if you want to show a tag cloud with your forum’s topic tags on a WordPress post or page, you might try to use the function bb_tag_heatmap, but that function only works if you’re on a BBpress page. You might also think of trying wp_tag_cloud, but since WordPress and BBpress are looking at different database tables for their tags, it won’t work either.
Here’s a pretty hacky way of making WordPress show BBpress topic tags when you’re not on a forum page. I put the code below into my WordPress theme’s sidebar.php.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
global $wpdb; $number_of_tags_to_show = 25; $largest = 25; //largest font in points $smallest = 4; //smallest font in points $tag_page_url = "http://www.mysite.org/forum/tags"; //url of your forum tags page $taglist = $wpdb->get_results("select name, term_id from bb_terms","ARRAY_N");//$taglist[index][name][term_id] for ($count = 0; $count < count($taglist); $count++)//use the term_id's to grab the count from bb_term_taxonomy { if($taglist[$count][0])//if theres a tag term { $query = "select count from bb_term_taxonomy where term_id = " . $taglist[$count][1]; $result = $wpdb->get_results($query, "ARRAY_N"); $term_count = $result[0][0]; $taglist[$count][2] = $term_count; } } //now the array is formatted like so: $taglist[index][name][term_id][count] $taglist = sort2d($taglist, 2); //now the array is sorted with more popular tag at the front $taglist = array_slice($taglist, 0, $number_of_tags_to_show);//truncate the array to show the correct number of tags $taglist = sort2d($taglist, 0, 'asc', TRUE);//order the array alphabetically by tag $min_count = 1; $spread = 9; if ( $spread <= 0 ) $spread = 1; $fontspread = $largest - $smallest; if ( $fontspread <= 0 ) $fontspread = 1; $fontstep = $fontspread / $spread; while (list($tag_index) = each($taglist)) { $tag = $taglist[$tag_index][0]; $count = $taglist[$tag_index][2]; $fontsize = round( $smallest + ( ( $count - $min_count ) * $fontstep ), 1 ); $count > 1 ? $title = $count . " topics" : $title = $count . " topic"; echo '<a style="font-size: ' . $fontsize . 'pt;" title="' . $title . '" href="' . $tag_page_url . '/'; echo $tag; echo '" rel="tag">'.$tag.'</a> '; echo "n"; } function sort2d ($array, $index, $order='desc', $natsort=FALSE, $case_sensitive=FALSE) { if(is_array($array) && count($array)>0) { foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index]; if(!$natsort) ($order=='asc')? asort($temp) : arsort($temp); else { ($case_sensitive)? natsort($temp) : natcasesort($temp); if($order!='asc') $temp=array_reverse($temp,TRUE); } foreach(array_keys($temp) as $key) (is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key]; return $sorted; } return $array; } |
Your website design gives that look like vintage and html 5 mixed Idk but looks awesome!