0

I am changing the banner in the header based on the page id:

 if(is_page(14) or is_page(16))
    { $class_name='bannerExp'; }
    if(is_page(18) or is_page(52) or is_page(22) or is_page(20))
    { $class_name='bannerD'; }
    if(is_page(27))
    {$class_name='bannerJ';}
     if(is_page(25))
    {$class_name='bannerS';}
   if(is_page(2))
    {$class_name='bannerH';}

<div class="<?php echo($class_name);?>">

class_name is a different css class that loads different size and background image(banner) when the if statement is true:

.bannerExp{width: 100%; height: 440px; background-image: url(img/yyy.png);background-repeat: no-repeat;}
.bannerDev{width: 100%; height: 440px; background-image: url(img/zzz.png);background-repeat: no-repeat;}

I want also to inlude text or images inside the banner div when one of the pages is loaded. How can I achieve that?

0

Just assign something to a variable and output that

    if(is_page(14) or is_page(16))
        { $class_name='bannerExp'; }
        if(is_page(18) or is_page(52) or is_page(22) or is_page(20))
        { $class_name='bannerD'; 
          $somevariable = 'test';
}
        if(is_page(27))
        {$class_name='bannerJ';}
         if(is_page(25))
        {$class_name='bannerS';}
       if(is_page(2))
        {$class_name='bannerH';}

    <div class="<?php echo($class_name);?>">
<?php (if $somevariable != '') { echo $somevariable;} ?>

That being said, this is a horrible way of doing things and you should look into custom page templates, rather than having to check for page id's and writing if statements for every case scenario... this defeats the point of having a cms.

  • if( is_page( array(18, 52, 22, 20) ) ) is shorter and less distractive. – Max Yudin Dec 1 '17 at 12:18
  • Thank you. I was abble to achieve what I needed. I will change the if statement as well. – Vanina Yordanova Dec 1 '17 at 13:50
  • Glad you got it working. Please set the issue as resolved. – Daniel Fonda Dec 1 '17 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.