• Resolved Mav3000

    (@mav3000)


    Hi All,

    I am using WordPress as a CMS. ‘Posts’ have various categories in two category sections – ‘Region’ and ‘Type’ – each Category parent then has sub-Categories – ‘North’, ‘South’ for the Region etc and ‘Residential’ and ‘Commercial’ etc for the Type Category Parent.

    When on the Theme page for say, Posts by Region, I want to return the Region Category, by using ‘get_the_category()’ or the_category() – but I only want to return the Category for the ‘Region’ Category Parent – and not the Category in the ‘Type’ parent.

    I hope this makes sense. Can anyone tell me how to specifically return a category from a certain cat parent and not all categories?

    Thanks for any help on this,

    Mav3000

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Mav3000

    (@mav3000)

    Basically I am trying to do this:

    <?php
      foreach((get_the_category()) as $cat) {
        if (
          $cat->cat_name!=='one' ||
          $cat->cat_name!=='two' ||
          $cat->cat_name!=='three' ||
          $cat->cat_name!=='four'
        ) echo $cat->cat_name . ' ';
      }
    ?>

    But it doesn’t seem to like me trying to use more than one category to exclude.

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

    (@mav3000)

    Michael that is perfect and works a treat – thank you very much indeed!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show Post Category but From Specific Category Parent’ is closed to new replies.