• Resolved robhav

    (@robhav)


    Hi

    I am trying to have a banner appear, only when on certain pages. The code I am currently using is:

    <div <?php if (is_page(’emotional-wellbeing’)) {?>class=”lookhere emotionalwellbeing”<?php } ?>></div>
    <div <?php if (is_page(‘healthy-eating-exercise’)) {?>class=”lookhere healthyeating_exercise”<?php } ?>></div>
    <div <?php if (is_page(‘general-health’)) {?>class=”lookhere generalhealth”<?php } ?>></div>

    So there are 3 conditions. What I need is another condition that states that if the page is anything other than these pages, there will a be different class used (and therefore a generic banner will be displayed).

    Sorry for asking a php newbie question, but this has been frustrating me for hours!

Viewing 4 replies - 1 through 4 (of 4 total)
  • wp_guy

    (@wp_guy)

    How about this:

    <div <?php
    
    if ( is_page('emotional-wellbeing') ) {
        ?>class="lookhere emotionalwellbeing"<?php
    } elseif ( is_page('healthy-eating-exercise') ) {
        ?>class="lookhere healthyeating_exercise"<?php
    } elseif ( is_page('general-health') ) {
        ?>class="lookhere generalhealth"<?php
    } else {
        // Your code here
    }
    Thread Starter robhav

    (@robhav)

    Thanks for your reply! I have tried to used an else statement, but can’t seem to get the syntax right. At the moment I’ve got the following but it is not parsing correctly:

    <div class="lookhere">
    <div <?php
    
    if ( is_page('emotional-wellbeing') ) {
        ?>class="lookhere emotionalwellbeing"<?php
    } elseif ( is_page('healthy-eating-exercise') ) {
        ?>class="lookhere healthyeating_exercise"<?php
    } elseif ( is_page('general-health') ) {
        ?>class="lookhere generalhealth"<?php
    } else {
        ?>class="lookhere contactus"<?php
    }
    
      </div></div>
    wp_guy

    (@wp_guy)

    Aw, sorry… forgot to close the div… Should be something like this:

    <div <?php
    
    if ( is_page('emotional-wellbeing') ) {
        ?>class="lookhere emotionalwellbeing"<?php
    } elseif ( is_page('healthy-eating-exercise') ) {
        ?>class="lookhere healthyeating_exercise"<?php
    } elseif ( is_page('general-health') ) {
        ?>class="lookhere generalhealth"<?php
    } else {
        ?>class="lookhere contactus"<?php
    }
    
    ?>></div>
    Thread Starter robhav

    (@robhav)

    Awesome. Thanks for your help!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Generic Banner specified in CSS’ is closed to new replies.