Posted By

vagrantradio on 09/09/10


Tagged

wordpress


Versions (?)

WordPress Exclude Category Slugs


 / Published in: PHP
 

Exclude category slugs, only shows parent cats.

  1. //template call
  2. <?php echo the_category_exclude(", ","featured,uncategorized,other,news,articles"); ?>
  3.  
  4. //functions file
  5. function the_category_exclude($separator=', ',$exclude='') {
  6. $toexclude = explode(",", $exclude);
  7. $newlist = array();
  8. foreach((get_the_category()) as $category) {
  9. if(!in_array($category->category_nicename,$toexclude) && ($category->category_parent == 0)){
  10. //$newlist[] = $category->cat_name;
  11. $newlist[] = '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';
  12. }
  13. }
  14. return implode($separator,$newlist);
  15. }

Report this snippet  

You need to login to post a comment.