• Resolved badjeros

    (@badjeros)


    I’m using

    <?php the_category(”) ?>

    to show the categorys that a given post belongs to in that post’s metadata.

    In cases where the post is in the category ‘uncategorized’ I would like to have no category listed, instead of it being specifically labelled ‘uncategorized’.

    Is there a way to hide that default category in a list of categories?

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

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

    Thread Starter badjeros

    (@badjeros)

    Perfect! Thanks for the swift solution.

    Where would this be inserted? Not a newbie to WP, but still have serious coding issues. 🙂

    With the help of the Template Hierarchy article, determine what Template is displaying the posts you are talking about (could be index.php). Then edit that Template and add the code.

    Thread Starter badjeros

    (@badjeros)

    I know this is stretching things, but I don’t suppose there’s a way to insert a comma after each categoy, excepting the final one, while still maintaing the Uncategorized filter functionality provided by MichaelH?

    <?php
    $igc=0;
    foreach((get_the_category()) as $category) {
        if ($category->cat_name != 'uncategorized') {
    if($igc != 0) { echo ', '; }; $igc++;
        echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';
    }
    }
    ?>
    Thread Starter badjeros

    (@badjeros)

    That does it very nicely. Thanks for your help alchymyth, I had no chance of figuring that one out on my own.

    I do it with CSS only because it is faster.
    Just add:
    .cat-item-1 {display:none;}
    changing the ID number if different.

    Hi there,

    I’m using the excellent paragrams theme for my blog.
    I want to hide certain categories from the metadata. I tried hard to do what’s described here in the forum, but it doesn’t seem to work.

    Here’s my code from the theme:

    <div class=”postmetadata”>
    <?php printf(__(‘%s’), get_the_category_list(‘ | ‘)); ?> ˑ 
    </div>

    Any help is very much appreciated.
    Thanks!

    Arthur

    Guys why don’t you just use plugins :S

    Here’s a plugin that hides any category from list and menus..
    ( WP Hide Categories )

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘hide ‘uncategorized’ in list of post’s categories’ is closed to new replies.