View Full Version : Exclude category names

01-14-2012, 03:12 AM
Hello, I'm trying to alter my site code to only retrieve certain categories. Specifically, I want to exclude a few category names from the basic retrieval code. Here is the code I currently have:

<!-- Begin #colRight -->
<div id="colRight">
if(get_option('boldy_blog')!='' && is_category(get_option('boldy_blog')) || post_is_in_descendant_category( get_option('boldy_blog'))){
$current = get_the_category();
$current_id= $current[0] ->cat_ID;
$categs_list = get_category_parents($current_id);
$pieces = explode("/", $categs_list);
$category_name = strtolower($pieces[0]);
$categs = get_cat_id($category_name);
<div class="rightBox">
<h2><?php echo get_cat_name(get_option('boldy_blog'));?> Categories </h2>
<ul >
$categories = get_categories('hide_empty=1&child_of='.$categs);
foreach ($categories as $cat) {
echo ('<li><a href="');
echo (get_category_link($cat->cat_ID).'">'.$cat->cat_name.'</a></li>');
<?php }}?>

<?php /* Widgetized sidebar */
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?><?php endif; ?>

<!-- End #colRight -->

Some of the categories I want to remove are called:

Around the Web

Thanks for the help!

01-14-2012, 03:44 AM
Is it WordPress?

01-14-2012, 03:45 AM
Yes, a Wordpress blog on my own site.

01-14-2012, 03:53 AM
Here is a link to my site (http://www.zoiology.com/category/blog/) if that helps. I'm trying to change the sidebar feature called "Blog Topics"

01-14-2012, 06:32 PM
I'm just sort of taking a stab at this one. Make a safe copy of your current script
before overwriting it. I'm thinking that instead of "get_categories", you will use
"list_categories" and specify the one's you want.

You currently are using the permalink (without an id number), but your categories
still have id numbers associated with them. View your categories in your admin and
note the id numbers for each one. You'll see in my example, I just put random
category numbers there ... switch those with the ones you want to appear in
your sidebar list.

<div class="rightBox">
<h2><?php echo get_cat_name(get_option('boldy_blog'));?> Categories </h2>
<ul >

Here are the types of things you'll be using online for information .. WP CODEX


Use the CODEX website for all of your specific customization needs: