• Resolved oldbag66

    (@oldbag66)


    i want to show content on all pages except on in the side bar, im usinh conditional statements but cant seem to get it right, here is my php:

    <?php if (is_page()) { ?>
    <p>something for all other pages goes here</p>
    <?php } elseif (is_page('37')) { ?>
    <p>something for page 37 only goes here</p>
    <?php } ?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • The problem is that the first statement, “is_page”, applies to all pages, including page 37, so it always uses the first statement.

    You want to reverse the order, so that you conditions start out specific, and then become more general.

    Also, you only need an “if” and “else” for two conditions:

    <?php
     if ( is_page('37')) {
     echo "<p>something for page 37 only goes here</p>";
     }
     else {
     echo "<p>something for all other pages goes here</p>";
     }
     ?>

    Thread Starter oldbag66

    (@oldbag66)

    thats great, im just learning about the conditionals, thanks

    No problem!

    Thread Starter oldbag66

    (@oldbag66)

    another similar problem im trying to get a conditional statement to apply to certain pages ie:

    <?php } else if (is_page('46','49','51','53')) { ?>

    cant get it to work or find info on this, i only want something to show on these pages.

    It won’t work on its own like that. The conditional statement needs to go if/else or if/elseif/else.

    Thread Starter oldbag66

    (@oldbag66)

    so you cant apply it to multiple pages at the same time rather than writing if else for each page

    You can apply it to as many pages as you want, but the conditions need to be ordered properly.

    This isn’t going to do anything because there isn’t an if to start the conditions, or an else to end them:

    <?php } else if (is_page('46','49','51','53')) { ?>

    If you want to have one page have code A, and then several pages have code B, and all the rest have code C, you want to start with the most specific, a single page, then the more broad, several pages, then the catch-all, like this:

    <?php
     if ( is_page('37')) {
     echo "<p>something for page 37 only goes here</p>";
     }
     elseif ( is_page('46','49','51','53')) {
     echo "<p>something for pages 46, 49, 51, and 53 goes here</p>";
     }
     else {
     echo "<p>something for all other pages goes here</p>";
     }
     ?>

    Does that make sense?

    Thread Starter oldbag66

    (@oldbag66)

    that does thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘condition staments help with excluding pages’ is closed to new replies.