Advertisement
alchymyth

exclude 36 children from the_category

Jul 28th, 2011
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. //
  2. //a filter function to exclude all child categories of cat 36 from the_category()
  3. //
  4. add_filter('the_category', 'the_category_exclude_parent_36');
  5.  
  6. function the_category_exclude_parent_36($list) {
  7.     global $post;
  8.     $categories = get_the_category( $post->ID );   
  9.     $thelist = ''; $separator = ', ';  
  10.     $i = 0;
  11.     foreach ( $categories as $category ) {
  12.         if( $category->category_parent != 36 ) :
  13.             if ( 0 < $i )
  14.                 $thelist .= $separator;
  15.                 $thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a>';
  16.             ++$i;
  17.         endif;
  18.     }
  19.     return $thelist;
  20. }
  21. //
  22. //end of the filter function to exclude all child categories of cat 36
  23. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement