hi
Needed to do this as well so improving on chavo's and nlex's code above (many thanks) this below will do what you want and give you exactly the same type of output as the_category() i.e. categories with links on them.
//exclude these from displaying
$exclude = array("Large Announcement", "Announcement", "News");
//set up an empty categorystring
$catagorystring = '';
//loop through the categories for this post
foreach((get_the_category()) as $category)
{
//if not in the exclude array
if (!in_array($category->cat_name, $exclude))
{
//add category with link to categorystring
$catagorystring .= '<a href="'.get_bloginfo(url).get_option('category_base').'/'.$category->slug.'">'.$category->name.'</a>, ';
}
}
//strip off last comma (and space) and display
echo substr($catagorystring, 0, strrpos($catagorystring, ','));
I have coded it as an exclude list of categories (i.e. don't show categories in the list) as I have fewer to exclude but you might want to do it exactly the way you said initially, i.e. only show the categories in your list, an include list. if so change:
$exclude = array("Large Announcement", "Announcement", "News");
to
$include = array("Large Announcement", "Announcement", "News");
and insert as many categories as you want to display (inside the brackets in double quotes and seperated by commas) and then change:
if (!in_array($category->cat_name, $exclude))
to
if (in_array($category->cat_name, $include))
a+
gar