Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 9th, 2011  |  syntax: PHP  |  size: 0.97 KB  |  views: 613  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function exclude_post_categories($excl='', $spacer=''){
  2.    $categories = get_the_category($post->ID);
  3.       if(!empty($categories)){
  4.         $exclude=$excl;
  5.         $exclude = explode(",", $exclude);
  6.         foreach ($categories as $child){
  7.           $parents = get_category_parents($child->cat_ID, FALSE, ',');
  8.           $parents = explode(',', $parents);
  9.           foreach($exclude as $excluded){
  10.            if (in_array($excluded, $parents)){
  11.                $excluded_children[] = $child->cat_ID;
  12.            }
  13.           }
  14.         }
  15.                 $thecount = count(get_the_category()) - count($excluded_children);
  16.         foreach ($categories as $cat) {
  17.                 $html = '';
  18.                 if(!in_array($cat->cat_ID, $excluded_children)) {
  19.                                 $html .= '<a href="' . get_category_link($cat->cat_ID) . '" ';
  20.                                 $html .= 'title="' . $cat->cat_name . '">' . $cat->cat_name . '</a>';
  21.                                 if($thecount>1){
  22.                                         $html .= $spacer;
  23.                                 }
  24.                         $thecount--;
  25.                 echo $html;
  26.                 }
  27.               }
  28.       }
  29. }