Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Exclude a Category from Sidebar Display WordPress

  • SOLVED

Hello, I am trying to exclude a certain category from being displayed in my sidebar; this is the code I am using today:

<h4><?php
foreach((get_the_category()) as $childcat) {
$parentcat = $childcat->category_parent;
if( $parentcat != 0 ) echo '<a href="' . get_category_link($parentcat) .'">' .get_cat_name($parentcat) .'</a>';
else echo '<a href="' . get_category_link($childcat) .'">' .$childcat->cat_name .'</a>';
}
?>


If a category is marked as both "featured" and something else, both of the categories are displayed - you can see this annoyingness in action on the sidebar of this page: [[LINK href="http://www.chitaskforce.org/criminalization/violence-criminalization/"]][[/LINK]]

I want to find out how I can exclude the "featured" category (ID 33) from the above.

Thanks for your help!

Answers (1)

2011-02-26

Pippin Williamson answers:



foreach((get_the_category()) as $childcat) {

$parentcat = $childcat->category_parent;
if ($childcat->cat_ID != 33)
{
if( $parentcat != 0 ) echo '<a href="' . get_category_link($parentcat) .'">' .get_cat_name($parentcat) .'</a>';

else echo '<a href="' . get_category_link($childcat) .'">' .$childcat->cat_name .'</a>';
}
}