• Resolved aldodager

    (@aldodager)


    hi to everyone

    im running a digital magazine, and above the post title im adding a line for the reader to know on which category is that post.. right now it looks this way:

    Featured, Fitness
    POST TITLE

    I would like to avoid showing FEATURED or MAIN ARTICLE in that line. So far I’m using:

    <?php $category = get_the_category();
    echo $category[1]->cat_name;
    ?>

    But i dont think that this code is what I need. Also, I don’t know how to link the Category name to that specific category. So finally I would only like to show:

    Fitness (linked to fitness category)
    POST TITLE

    instead of

    Featured (linked to this cat), Fitness (linked to this cat)
    POST TITLE

    Probably this has been resolved before but im not good at tweaking wordpress codes

    Thank you very much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • An example of excluding one (or more) categories displaying:

    <?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 aldodager

    (@aldodager)

    the code worked great!!!
    thank you very much!

    ronvil

    (@ronvil)

    Sorry, but i’m just beginning to customize wordpress themes. how can i edit

    <?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> ';
    }
    }
    ?>

    to exlude the categories that i do not want to appear? Thank you in advance!

    ronvil

    (@ronvil)

    Sorry for posting again. i would like to clarify my question above.

    for example, i have the following categories

    1. Category 1
    1. Category 1.1
    2. Category 1.2
    3. Category 2

    Then, under the post title, i want to put a link to the category archive for “Category 1.1” ONLY and not have the other categories of the same post appear. How do i do this? thanks again!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Excluding a category’ is closed to new replies.