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>";
}
?>
thats great, im just learning about the conditionals, thanks
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.
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?