/ Published in: PHP
Exclude category slugs, only shows parent cats.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//template call <?php echo the_category_exclude(", ","featured,uncategorized,other,news,articles"); ?> //functions file function the_category_exclude($separator=', ',$exclude='') { $toexclude = explode(",", $exclude); $newlist = array(); foreach((get_the_category()) as $category) { if(!in_array($category->category_nicename,$toexclude) && ($category->category_parent == 0)){ //$newlist[] = $category->cat_name; $newlist[] = '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>'; } } return implode($separator,$newlist); }