• I am trying to display images if a child category is selected however when a child category is not selected I want to display a message saying its not available. The below code works to display the images however I cannot seem to correctly add the code that displays message if no child category is selected.

    <?php
    foreach((get_the_category()) as $childcat) {
    if (cat_is_ancestor_of(210, $childcat)) {
    
    echo '<img src="/wp-content/themes/Bootstrap/images/flags/';
    echo $childcat->slug;
    echo '.png" alt="';
    echo $childcat->cat_name;
    echo '" title="';
    echo $childcat->cat_name;
    echo '" style="width:28px;height:20px;border-radius:20px;"> ';
    
    }}
    ?>

    Below is a working conditional however it does not display all the child categories like the code above.

    <?php
    
     if (is_category_or_sub(210)) {
    
    	 echo '<img src="/wp-content/themes/Bootstrap/images/flags/';
    echo $childcat->slug;
    echo '.png" alt="';
    echo $childcat->cat_name;
    echo '" title="';
    echo $childcat->cat_name;
    echo '" style="width:28px;height:20px;border-radius:20px;"> ';
    
    } else {
    echo 'Sorry This Movie Is Not Available';
    }
    
     ?>

    Here is it in action: http://netflix.rhgfx.com/life-itself/

    its the availability column on the left.

  • The topic ‘Child Category Conditional’ is closed to new replies.