• The 2014 theme has the follow code to list the categories the current post is included in:

    <span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>

    I would like to list the categories, but exclude some if possible.

    Stupidly I started to use this code thinking it was based on the current post. But it’s the site as a whole!

    <span class="cat-links">Categories: <?php wp_list_categories('orderby=name&show_count=0&hierarchical=0&exclude=2,3&title_li=&style=none'); ?> </span>

    Can anyone help me please?

Viewing 1 replies (of 1 total)
  • Thread Starter wilsonf1

    (@wilsonf1)

    A bit more research and I now have a solution.

    Using some of the examples here as my starting block (http://wordpress.org/support/topic/how-to-exclude-categories-from-get_the_category_list?replies=11#post-1894240), I have created this:

    <?php
    $anyCategories = false;
    foreach((get_the_category()) as $category) {
        if (
            $category->cat_ID=='2' ||
            $category->cat_ID=='3' ||
            $category->cat_ID=='7' ||
            $category->cat_ID=='XXX') continue;
    
        $anyCategories = true;
        if ($anyCategories == true) {
            echo '<span class="cat-links">Topic: ';
        }
        $category_id = get_cat_ID( $category->cat_name );
        $category_link = get_category_link( $category_id );
        echo '<a href="'.$category_link.'">'.$category->cat_name.'</a>';
    }
    if ($anyCategories == true) {
        echo '</span>';
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Can I list which categories the current post is in – but exclude some?’ is closed to new replies.