How To Exclude Categories In The Mandigo Theme

I was recently contacted by an individual that was having issues trying to exclude certain categories from being shown in the Mandigo theme. While I have never personally used the Mandigo theme or even taken a look at it, I took it as a chance to expand my knowledge of WordPress themes.

Editing the code in sidebar.php

With the default setup, the code for displaying the categories are placed in the sidebar.php file. Make your way into the WordPress Theme Editor which can be found inside of your Admin Dashboard under the Appearance tab.

Once you have the editor open, click on Sidebar (sidebar.php) located on the right hand side. This will open up the sidebar.php file allowing you to edit the code.

Scroll down in the file almost all the way down to the bottom. The code that you are looking for is listed below.

<?php
	// the list of categories
	wp_list_cats(
		array(
			'sort_column'  => 'name',
			'optioncount'  => 1,
			'hide_empty'   => 0,
			'hierarchical' => 1,
		)
	);
?>

This is the code that currently displays the list of categories. Now, for whatever reason(s), wp_list_cats is actually old deprecated code that isn’t used anymore. So instead of continuing using that code we are going to use the more current version as well as change how the code looks.

Delete all of the code that is in between the <?php and ?> tags. Once you have it deleted replace it with the following.

wp_list_categories(
	'sort_column=name
	&optioncount=1
	&hide_empty=0
	&hierarchical=1'
);

The above code still provides the exact same configuration just with the updated WordPress function. Now that we have the new code updated, lets add in the piece of code to exclude certain categories from displaying.

wp_list_categories(
	'sort_column=name
	&optioncount=1
	&hide_empty=0
	&hierarchical=1
	&exclude=1,2,3'
);

In the example above I bolded and underlined the code that does the actual hiding of categories. Currently the code hides the categories with IDs of 1, 2 and 3 but this most likely isn’t going to fix your problem. In order to keep a certain category from showing you need to find the ID of that particular category.

Find the ID of a category

To find the category, click on the Categories link in the Admin Dashboard located under the Posts section. Once the list is loaded, hover your mouse over the category that you would like to hide. The ID of the category will be displayed in the status bar at the bottom of your browser after &cat_ID=.

Make sure you write this number down (or at least remember it) and head back into the WordPress Theme Editor. Quick note: If you’d like to hide more than one category, write down the ID’s of those categories as well.

Back to sidebar.php

Back inside of the editor and inside of the sidebar.php file, find the code that I had you change earlier. Remember the small piece that we added onto the end?

&exclude=1,2,3

The numbers in the above code are the category IDs. So if you wanted to hide the category with an ID of 49 you would replace the 1,2,3 with 49.

&exclude=49

If you want to hide more than one category just insert the category IDs with a comma separating each number. In the first example above, the categories with IDs of 1, 2 and 3 would be hidden.

That is it for this relatively easy tutorial. As a quick site note, if you use parent/child categories and choose to hide a parent category, the child categories of that parent will also be hidden as well.

Happy coding!

Feedback!

If you read this post and understood it great! Let me know in the comments below. If you are still having issues and can't get it figured out, you are more than welcome to leave a comment or send me an email using the contact form and I'll do what I can to help!

Leave a Reply