Forums

[resolved] Multiple conditionals without using echo? (3 posts)

  1. multiplier
    Member
    Posted 4 years ago #

    In page.php, I need a conditional that says, "If it's the About page, display this text, if it's the Contact page display this text, and for all other pages, display this text".

    I've seen examples of multiple conditionals on the Codex page, but they all use an echo. I have PHP functions within my text that won't execute within the echo. Can anyone demonstrate how to make this work?

  2. iridiax
    Member
    Posted 4 years ago #

    Here is the format I use (you can use php between these):

    <?php if (is_page('about') ) { ?>
    <p>About text</p>
    <?php } elseif (is_page('contact') ) { ?>
    <p>Contact text</p>
    <?php } else { ?>
    <p>Default text</p>
    <?php } ?>
  3. multiplier
    Member
    Posted 4 years ago #

    Brilliant, thank you! It was the curly brace before the elseif I had neglected.

Topic Closed

This topic has been closed to new replies.

About this Topic