• Resolved maisteriharju

    (@maisteriharju)


    Topic may be confusing but I couldn’t think of better one.

    I’m using conditional tags and is_page -function to get some code to some particular pages. I need to have different kind of layout on different pages so is_page -code seems to work perfectly for this.

    I’ve been doing it like this:

    <?php
    if (is_page('PageName1'))
    {
    echo "code here";
    }
    
    elseif (is_page('PageName2'))
    {
    	echo "same code here";
    }
    
    elseif (is_page('PageName3'))
    {
    	echo "different code here";
    }
    
    ?>

    As you noticed I have same code for some of the pages. I have so many pages that it’s kind of frustrating to copy the elseif-lines many times and I started to wonder if there is some easier way. I should propably also mention that I’m not very familiar with this kind of coding as you may have already guessed.

    Is there any way to have many pages inside one is_page -code – like this:

    <?php
    if (is_page('PageName1', 'PageName2'))
    {
    echo "code here";
    }
    elseif (is_page('PageName3'))
    {
    	echo "different code here";
    }
    
    ?>

    It would be much easier. Is there AND or some similar code which could be used to make it work?

    Thanks for help.

    -TH

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    This way will work in WordPress 2.3.3:
    if (is_page('PageName1') || is_page('PageName2'))

    The || is an “or”.

    Starting with WordPress 2.5, this will work:
    if (is_page(array('PageName1', 'PageName2')))

    Thread Starter maisteriharju

    (@maisteriharju)

    Ok. I found out one simplier solution:

    <?php
    if (is_page(‘PageName1’) || is_page(‘PageName2’))
    {
    echo “code here”;
    }
    elseif (is_page(‘PageName3’))
    {
    echo “different code here”;
    }

    ?>

    That’s close enough.

    Thread Starter maisteriharju

    (@maisteriharju)

    Thanks Otto42! We wrote the message at the same time. ?? Array is even simplier way. Thanks for the help!

    – TH

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘is_page -code with multiple pages in one?’ is closed to new replies.