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?

1 Answer 1

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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