0

I'm trying to create a PHP 'if' statement that tells an image to display on certain pages in Wordpress. What I'm trying to do is shown below, but I think the syntax is incorrect.

I'm trying to say "If the page displayed equals 'about' or 'gallery' and that page is not 'services', go ahead and display the image.

Here's the section of code that you should be able to analyze and see where I went wrong:

<?php if(is_page('about' || 'gallery') && (is_page != 'services')) { ?>
 <li><img id="profile_pic" alt="DermaKare (Official Fan Page)" src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/50556_123510051042639_3343345_n.jpg" class="photo img" /></li>
            <?php } ?>
            <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Banner") ) : ?>
        <?php /*?><p><a href='<?php bloginfo('siteurl')?>/wp-admin/widgets.php'>Widgetize this sidebar</a></p><?php */?>
            <?php endif; ?>

Thanks in advance for any help on this.....

1
  • I think it's just the first half of the code that needs to be looked at, not the bottom. Commented Dec 16, 2011 at 22:10

3 Answers 3

3

If a page is about or gallery then it never is services. So you can spare that not part.

Next to that you need to call the function twice:

if (is_page('about') || is_page('gallery'))
{
    # then
}

This should do it. Wrapped into your code this should look like:

<?php if  (is_page('about') || is_page('gallery')) { ?>
Sign up to request clarification or add additional context in comments.

Comments

1
if ( ( is_page('about') || is_page('gallery') ) && !is_page('services') )

watch the brackets.

edit: and what @hakre said, if it's about or gallery, it never is services

Comments

0
<?php if( (is_page('about') || is_page('gallery') ) && (!is_page('services') ) {
 echo "<li><img id=\"profile_pic\" alt=\"DermaKare (Official Fan Page)\" src=\"http://profile.ak.fbcdn.net/hprofile-ak-snc4/50556_123510051042639_3343345_n.jpg\" class=\"photo img\" /></li>";
} ?>

this should work

3 Comments

Hi Mike, I tried it and it didn't work for some reason. I know your code makes sense, and I double checked how I'm identifying the page and it seems correct. Any other ideas? I could let you login if you want to look yourself.....let me know
@RobMyrick It seems I forgot to close (!is_page('services') ). It should be (!is_page('services') ) ). Try it now
Mike I used your code intertwined with an answer below. thanks for your help

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.