Hi,
Instead of using a plugin, you could create a function to store all the categories you wish to exclude, and then reference it in the ‘exclude’ argument of the wp_list_categories
function, which is WordPress function. This would list all your categories except for the ones stored in the exclusion function.
Here’s a very simple way of doing this:
1. Paste the following code into your theme’s functions.php file:
function userf_cat_exclusion_list() {
$exclusion_list = '';
return $exclusion_list;
}
2. Add all the category IDs you wish to exclude in the second line. Ex.:
$exclusion_list = '1,3,4,8';
3. Use the wp_list_categories function to display your categories and call the userf_cat_exclusion_list
in the exclude
parameter like so:
<?php wp_list_categories(array(
'exclude' => userf_cat_exclusion_list(),
));
?>
You can add other arguments to the function, but you need to do so before ));
. Example:
<?php wp_list_categories(array(
'exclude' => userf_cat_exclusion_list(),
'order<code>=></code>DESC
,
‘title_li’ = ”
));
?>
This way, you won't have to copy/paste the category IDs in the <code>exclude</code> argument every time you call the wp_list_categories
function, which is rather helpful if you wish to exclude many categories.
I hope this helps!
`
@derlars Hi, i checked the plugin with 3.2.1 and it worked. Can you explain your problem?
Huseyn’s post made me realize I had messed up the code box in my last example. It should be:
<?php
wp_list_categories(array(
'exclude' => userf_cat_exclusion_list(),
'order' => 'DESC',
'title_li' = ''
));
?>
I usually try to avoid using plugins for functionality that can be easily achieved using WP default functions, but I realize this is a personal preference.
Marventus, I avoid using plugins for funcionality like this, too. But i think there is a lot of people who afraid to open a code editor and write codes like you wrote above. I made this plugin for them 🙂 This plugin has lovely admin screen ( http://nxsn.com/wp-content/uploads/2011/10/wp-hide-pages-plugin.png ) Hiding a page is very simple, click it and hided 🙂
BTW this plugin use wp_list_categories method’s exclude parameter as you guess. Nothing more.
Hi Huseyn,
It is indeed true that many people are afraid of editing theme files and the likes.
I hope derLars will be able to use your plugin if that’s what he prefers.
Also, I just took a look at your plugin’s code and I saw no reason why it shouldn’t be working on 3.2.1.
Cheers!
Try this
$wphc_options = get_option(‘wphc_options’);
echo wp_list_categories(substr($wphc_options[‘excluded’],0,-1)); ?>