• Resolved frescova

    (@frescova)


    I want to display a specific block of html when viewing an archive page based on on category.

    I have a category “news (id 1)” with 5 children categories;

    If I use (is_category (‘1’)) the html only appears when the news category is being browsed, but if I go to any of the children categories the html does not display;

    I know I can use an array, is_category(array(1,’news-cat-1′,’news-cat-2′)); but then I have to manually edit the code every time I add a child category to news.

    Is there a way to make it so that when the user is viewing the news category or any of it’s children the html display?

    thanks in advance for any guidance..

Viewing 7 replies - 1 through 7 (of 7 total)
  • Maybe this will help:

    <?php
    $current_cat = intval( get_query_var('cat') );
    $news = get_cat_ID('news');
    $taxonomy = 'category';
    $children = get_term_children( $news, $taxonomy );
    if (in_array($current_cat, $children)) {
      echo 'current category is a child of the news category';
    }
    ?>

    Thread Starter frescova

    (@frescova)

    Thanks,
    I’ll give it a shot…

    Thread Starter frescova

    (@frescova)

    OK – that sort of worked…

    It displays the html I want for all children categories, but now it does not display it for the parent category…

    Any ideas

    Thanks again for your help

    Sorry, wouldn’t you need something like:

    if (in_array($current_cat, $children) && is_category ('1')) {
    Thread Starter frescova

    (@frescova)

    nope – now it does not bring back anything at all…

    Here’s what I have:

    <?php
    $current_cat = intval( get_query_var('cat') );
    $news = get_cat_ID('Press Room');
    $taxonomy = 'category';
    $children = get_term_children( $news, $taxonomy );
    if (in_array($current_cat, $children) && is_category('428')) {
    ?>

    428 is the “Press Room” Category ID – I have – Press room has the child category “Press Releases” and Press Realeses has children categories of 2010, 2009, etc…

    Thanks again…

    Darn—not && that means AND

    so
    &&
    should be
    ||

    Thread Starter frescova

    (@frescova)

    Sweet ??
    Thanks for your help Michael!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Using is category to display specific content’ is closed to new replies.