• Hi,

    I’m trying to echo a value from an array with several names of categories.
    The problem is that I can’t figure out how to echo the specific value (=the category) rather than the word “Array”.
    Could you help me? Thanks!

    function cat_background_image (){
    
    $category_class = array('wissen', 'meinung', 'wirtschaft'); //category_names
    
    if ( is_single() ) {
    
    if(in_category($category_class))  echo  'class="bg_' .$category_class. '" ';
    
    } else {
    
    if(is_category($category_class))  echo  'class="bg_' .$category_class. '" ';
    
    }
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • I think this is what you want (UNTESTED). Replace this:

    if(in_category($category_class))  echo  'class="bg_' .$category_class. '" ';

    with this:

    foreach ($category_class as $cat_class ) {
       if (in_category($cat_class)) {
          echo  'class="bg_' .$cat_class. '" ';
          break;
       }
    }

    Use a similar replacement for the is_category() test.

    Thread Starter Julson

    (@julson)

    Oh yeah, it works ?? And again it’s the loop! ?? Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘is_category / in_category -> echo value from array’ is closed to new replies.