Hi, today I’m giving you the php code to display the list of child categories in Thesis Archive Intro.
Why this snippet? Well, imagine you have a rather complex website with a lot of categories and you would like to make the navigation easier for your visitors… While there is a lot of plugins and php snippets to create a breadcrumps that help you visitors to find their way towards the home page, I have not often seen the php used to help your visitors find their way towards the deepest parts of your content.
Now you have an example of such a code. Simply copy-paste this php snippet to your custom_functions.php file of your Thesis and have fun!
/* display a list of sub categories */
add_filter('thesis_archive_intro','custom_list_category_children',10,1);
function custom_list_category_children($html) {
if(is_category()) {
global $wpdb, $wp_query;
$children = $wpdb->get_results( "SELECT term_id FROM {$wpdb->term_taxonomy} WHERE parent = {$wp_query->queried_object->term_id}" );
if(count($children) != 0) {
$args = array(
'taxonomy' => 'category',
'title_li' => '',
'use_desc_for_title' => 1,
'echo' => 0,
'child_of' => $wp_query->queried_object->term_id
);
$list = wp_list_categories($args);
$output = '<div id="category_children_list" class="format_text"><h4>Sub categories</h4><ul class="sub_categories">'. $list .'</ul><div class="clear"></div></div>';
$html = substr_replace($html, $output, -7, 0);
}
}
return $html;
}Sure, you may adjust the output of the snippet and the CSS applied to it, but this is just a simple trame how to do it.
Feel free to ask questions in comments.




Loading...




{ 5 comments… read them below or add one }
Salut Serge
T’as oublié mes communications au sujet du CSS pour la liste des catégories, mentionnant la problématique du z-index pour IE ?
I posted a variant of the function you posted for “Parent” catégories, this one look nicer. http://diythemes.com/forums/showthread.php?67657-And-is-this-possible&p=306247#post306247
But unless you (as I did) add the categories “array” in the conditional, the menu list don’t show up in the child categories. I found a bit of snippet for that, but fail to integrate it. It would be fun to have the menu-list to show up on the parent & child, no ?
Pierre
Hi Pierre, I just fixed the whole thing, finally it was so easy and evident that we were 3 to miss it… the trick was to add css class menu to the <ul> tag of the category list…
one step more to the thesis magazine style child theme!
cheers,
serge
Salut
Fixed what ? Sure the default Thesis class is “menu”. Same as adding menus, like :
wp_nav_menu( array( ‘theme_location’ => ‘danish-menu’, ‘menu_class’ => ‘menu’, ‘container_id’ => ‘menu’ ) ); //or change prefix for the Class and ID for different styling. Thesis default is: ‘menu’.
There is still the problem of z-index.
Pierre
have you tried
.custom .menu {
z-index:auto;
}
?
Hi
IE8 is dead meat, when it come to menus. z-viens fou à essayé. The goddam sub-menu just don’t want to show up over the next line of parents.
So, horizontal list (with sub-list) on multi-lines is no good for IE8.
Pierre