• Resolved mcbest

    (@mcbest)


    Hi All,

    Need some basic PHP help please!

    I’m building a navigation menu that will display a different background image depending on which page is being viewed.

    I’m trying to apply an ID to an unordered list and then with CSS, assign a different background for each <UL id=”name”>. I’m hoping that this condition can apply to sub-pages too.

    I can get it to work for one page but when I try to introduce more IF statements, it all goes wrong!

    Currently works for one page:

    <ul<?php
    if (is_page(About))
    {
    echo ” class=\”about\””;
    }
    ?>>

    Doesn’t work but is more like what I want to achieve:

    <ul<?php

    if ( is_page(‘home’) || $post->post_parent == ’65’ )
    // the page is “Home”, or the parent of the page is “Home”
    {
    echo ” class=\”home\””;
    }

    } elseif ( is_page(‘about’) || $post->post_parent == ’47’ ) {
    {
    echo ” class=\”about\””;
    }

    } elseif ( is_page(‘news’) || $post->post_parent == ’26’ ) {
    {
    echo ” class=\”news\””;
    }

    } elseif ( is_page(‘contact’) || $post->post_parent == ’24’ ) {
    {
    echo ” class=\”contact\””;
    }

    } else {
    {
    echo ” class=\”home\””; } // just in case we are at an unclassified page, perhaps the home page
    }
    ?>

    I hope I explained this clearly and that someone can help.

    Many thanks,

    McBest

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

The topic ‘Multiple IF conditions’ is closed to new replies.