admin管理员组文章数量:1406178
I am trying to write an if condition with 3 statements but it keeps crashing the site. Here is my statement, can you please advise what the issue is.
<?php if (is_page ('20')){?>
print this
<?php elseif (is_page ('50')){?>
then print this
<?php } else { ?>
print this
<?php } ?>
I am trying to write an if condition with 3 statements but it keeps crashing the site. Here is my statement, can you please advise what the issue is.
<?php if (is_page ('20')){?>
print this
<?php elseif (is_page ('50')){?>
then print this
<?php } else { ?>
print this
<?php } ?>
Share
Improve this question
asked Nov 25, 2019 at 2:12
DarrenLeeDarrenLee
257 bronze badges
2 Answers
Reset to default 4You're missing }
before elseif
:
<?php if (is_page ('20')){?>
print this
<?php } elseif (is_page ('50')){?>
then print this
<?php } else { ?>
print this
<?php } ?>
Remove the PHP tags and you'll see why:
if ( is_page( '20' ) ) {
elseif ( is_page( '50' ) ) {
} else {
}
You may write the statement in only one, short row:
print (is_page('20') ? "my output for page 20" : (is_page('50') ? "my output for page 50" : "my output for anything else") );
Important: Brackets must be in the right order like (statement ? if-result : else-result)
where the "else-result" is a 2nd nested statement, so it looks like (statement-1 ? 1st-if-result : (statement ? 2nd-if-result : last-else-result) )
Good luck!
本文标签: Conditional statement with three condition
版权声明:本文标题:Conditional statement with three condition 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744971420a2635255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论