@xs650
Actually, the categories tree on EBarney’s link was not made by the Collapsing Categories plugin. I retrieved the category items with the api get_categories and build the tree in php. All the scripts were put in the theme file we made.
Below is the scripts we use to display the categories. There are some lines of code that will replace the original rss with feedburner’s. But it should work fine even if you don’t have feedburner plugin.
<?php
$args=array(
'orderby' => 'id',
'hide_empty' => '0' // this is the option to get empty category
);
$categories=get_categories($args);
$map_parent = array();
//create a mapping array to store parents and children
//example: map_parent[23] = {24,25,26,27}
foreach($categories as $category) {
if($category->parent == 0) continue;
if(!isset($map_parent[$category->parent])){
$subcat = array();
}else{
$subcat = $map_parent[$category->parent];
}
$subcat[$category->term_id] = $category;
$map_parent[$category->parent] = $subcat;
}
//A loop for the categories who are at the highest level
foreach($categories as $category) {
if($category->parent != 0) continue;
display_entry($category, $map_parent);
$sub_cat = $map_parent[$category->term_id];
if( sizeof($sub_cat) != 0) {
echo '<div id = '.$category->term_id.'style="display:none">';
echo '<ul style="margin-left:20px;">';
hierarchy_loop($sub_cat, $map_parent);
echo '';
echo '</div>';
}
}
//This is a recursive function
function hierarchy_loop($category_list, $map_parent){
foreach($category_list as $cat){
display_entry($cat,$map_parent);
$sub_cat = $map_parent[$cat->term_id];
if(sizeof($sub_cat) != 0) {
echo '<div id = '.$cat->term_id.' style="display:none">';
echo '<ul style="margin-left:20px;">';
hierarchy_loop($sub_cat, $map_parent);
echo '';
echo '</div>';
}
}
}
//This function is used to display all the content in each category
function display_entry($category,$map_parent){
global $feedburner_settings;
echo '<li>';
echo '<a>term_id ) . '" title="View all posts in '. $category->name . '">' . $category->name.'</a>';
//Get feedburner url. If exists, use feedburner. Otherwise use the original one.
$rss_uri = htmlentities($feedburner_settings['feedburner_category_'.$category->term_id]);
if(trim($rss_uri) != ''){
$uri = str_replace('https://feeds.feedburner.com/','',$rss_uri);
echo '(<a>term_id]).'">RSS</a>)';
echo '(<a href="https://feedburner.google.com/fb/a/mailverify?uri='.$uri.'&loc=en_US">E-mail</a>)';
}else{
echo '(<a>term_id ).'">RSS</a>)';
}
echo '('. $category->count .')';
if(array_key_exists($category->term_id,$map_parent)){
echo '<a>term_id.'" href="javascript:void();"onclick="javascript:toggle('.$category->term_id.')"><font color="black"> ?</font></a>';
}
echo'</li>';
}
?>
<script language="javascript">
var $myjQuery = jQuery.noConflict();
function toggle(id){
var subcat=document.getElementById(id);
var collapse = document.getElementById('a'+id);
if(!subcat||!collapse)return true;
if(subcat.style.display=="none"){
$myjQuery('#'+id).slideToggle('slow');
collapse.innerHTML = '<font color="black">▼</font>';
} else {
$myjQuery('#'+id).slideToggle('slow');
collapse.innerHTML = '<font color="black">?</font>';
}
return true;
}
</script>