Exclude a category displaying under posts:
<?php
foreach((get_the_category()) as $category) {
if ($category->cat_name != 'uncategorized') {
echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
}
}
?>
Perfect! Thanks for the swift solution.
Where would this be inserted? Not a newbie to WP, but still have serious coding issues. 🙂
With the help of the Template Hierarchy article, determine what Template is displaying the posts you are talking about (could be index.php). Then edit that Template and add the code.
I know this is stretching things, but I don’t suppose there’s a way to insert a comma after each categoy, excepting the final one, while still maintaing the Uncategorized filter functionality provided by MichaelH?
<?php
$igc=0;
foreach((get_the_category()) as $category) {
if ($category->cat_name != 'uncategorized') {
if($igc != 0) { echo ', '; }; $igc++;
echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';
}
}
?>
That does it very nicely. Thanks for your help alchymyth, I had no chance of figuring that one out on my own.
I do it with CSS only because it is faster.
Just add:
.cat-item-1 {display:none;}
changing the ID number if different.
Hi there,
I’m using the excellent paragrams theme for my blog.
I want to hide certain categories from the metadata. I tried hard to do what’s described here in the forum, but it doesn’t seem to work.
Here’s my code from the theme:
<div class=”postmetadata”>
<?php printf(__(‘%s’), get_the_category_list(‘ | ‘)); ?> ˑ
</div>
Any help is very much appreciated.
Thanks!
Arthur
Guys why don’t you just use plugins :S
Here’s a plugin that hides any category from list and menus..
( WP Hide Categories )