Archive for September, 2011

We moved to

We moved to another dimension -

Leave a comment

New Hack for Displaying a Category / Subcategory Menu on WordPress


This post is very similar to the last one, but now we will show also subcategories onthe menu.

Again, you just have to copy and paste the code bellow wherever you want on your theme files.

You can also play with its CSS styles, so using the ids divcateg, ulcateg and the dynamic generated licateg_[category slug], ulsubcateg_[subcategory slug] and licateg_[subcategory slug]. You may change the category / subcategories menu appearance.

$args = array(
'type'                     => 'posts',
'orderby'                  => 'name',
'order'                    => 'ASC',
'hide_empty'               => 1,
'hierarchical'             => 1,
'taxonomy'                 => 'category',
'pad_counts'               => false );

$categories = get_categories($args);
	echo '<div id="divcateg"><ul id="ulcateg">';
	foreach ($categories as $category) {
		echo '<li id="licateg_'.$category->slug.'"><a href="'.get_bloginfo('siteurl')."/".$category->slug.'">'.$category->cat_name.'</a>';
		$subcategories=  get_categories('child_of='.intval($category->cat_ID));
				foreach ($subcategories as $subcategory) {
					echo '<ul id="ulsubcateg_'.$subcategory->slug.'">';
					echo '<li id="licateg_'.$subcategory->slug.'"><a href="'.get_bloginfo('siteurl')."/".$category->slug."/".$subcategory->slug.'">'.$subcategory->cat_name.'</a></li></ul>';
		echo '</li>';
	echo '</ul></div>';


Leave a comment

%d bloggers like this: