Exclude categories from loop?
I have the following code that grabs all the categories that the post has
been categorised in. I want to exclude certain categories but just putting
in exclude=1066 within the usual places doesn't seem to work.
The category 1066is actually a parent category, I want to exclude it and
all of it's child categories.
<?php $categories = wp_get_post_categories( $post->ID, array( 'fields' =>
'ids' ) );
$separator = '';
if ( $categories ) {
    $cat_ids = implode( ',' , $categories );
    $cats = wp_list_categories( 'title_li=&style=none&echo=0&include=' .
$cat_ids );
    $cats = rtrim( trim( str_replace( '',  $separator, $cats ) ),
$separator );
    echo  $cats;
}?>
This code is taken from
http://codex.wordpress.org/Template_Tags/wp_list_categories in the section
"Display Categories Assigned to a Post"
 
No comments:
Post a Comment