How to Display A List of Child Categories in Thesis Archive Intro

by on 2012/01/24 updated January 24, 2012

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.

Liked this article ? Get more into your inbox !

Liked this article? Get updates (it's free)

Liked this article? Enter your name and e-mail in the form on your right, to get the blog updates and promotions from thesistut.com.

{ 5 comments… read them below or add one }

Pierre February 16, 2012 at 22:49

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

Reply

Serge Liatko February 19, 2012 at 12:41

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

Reply

Pierre February 19, 2012 at 21:22

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

Reply

Serge Liatko February 21, 2012 at 13:37

have you tried

.custom .menu {
z-index:auto;
}

?

Reply

Pierre February 22, 2012 at 12:05

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

Reply

Leave a Comment

Previous post:

Next post: