Viewing 4 replies - 1 through 4 (of 4 total)
  • Exclude a category displaying under posts:

    <?php
    foreach((get_the_category()) as $category) {
        if (!in_array($category->cat_name,array('cat1_to_exclude','cat2_to_exclude','cat3_to_exclude')) ) {
        echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
    }
    }
    ?>

    Thread Starter Anders Norén

    (@anlino)

    Thanks! However, is there any way to change the code so I can specify what categories to include, as opposed to what categories to exclude? Seeing how my blog has a grand total of 67 categories, of which I would want to exclude 64.

    if (in_array($category->cat_name,array('cat1_to_include','cat2_to_include','cat3_to_include')) ) {
    Thread Starter Anders Norén

    (@anlino)

    Thanks, that did it!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Include only specific categories in the_category’ is closed to new replies.