WordPress.org

Ready to get started?Download WordPress

Forums

exclude categories by ID in the_category (4 posts)

  1. Maxaud
    Member
    Posted 5 years ago #

    How would I go about showing the categories a post belongs to while excluding certain categories from the list? Is there a different template tag that would work better than the_category?

    Thanks in advance!

  2. jllamosas
    Member
    Posted 4 years ago #

    Did you find the solution for this issue? Im finding the solution too. Thanks!

  3. themespedia.com
    Member
    Posted 4 years ago #

    Exclude ONE category by ID (use the_category):
    (Eg: Exclude the Category ID=10)
    <?php foreach((get_the_category()) as $cat) { if (!($cat->cat_ID==10)) echo '<a href="' . get_bloginfo('url') . '/category/' . $cat->category_nicename . '/">'. ' - ' . $cat->cat_name . '</a>';} ?>

    Exclude MULTI categories by ID (use the_category):
    (Eg: Exclude 3 Categories ID=10,20,30)
    <?php foreach((get_the_category()) as $cat) { if (!($cat->cat_ID=='10' || $cat->cat_ID=='20' || $cat->cat_ID=='30')) echo '<a href="' . get_bloginfo('url') . '/category/' . $cat->category_nicename . '/">'. ' - ' . $cat->cat_name . '</a>';} ?>

    It will work for you!

  4. rgbk
    Member
    Posted 4 years ago #

    EXACTLY what i needed.
    Thanks a mil.

Topic Closed

This topic has been closed to new replies.

About this Topic