我需要以下替代 if-else 语法的帮助。我经常使用它,它的成功率高达 99.999999%。在这里,由于某种原因,它不会:
if ( get_row_layout() == 'spacer' ) :
$spaceheight = get_sub_field('spacer_height');
// The Alternative Syntax: if... else statement without a colon
// Once these two lines are removed OR changed into "if ( some
// condition ) : some stuff; endif;" syntax >> the error goes
// away.
if ( $spaceheight && ( 0 !== $spaceheight ) )
echo "<div class='basf-spacer' style='display: block; width: 100%; height: {$spaceheight}px; background: transparent; padding: 0; margin: 0; font-size: 0; line-height: 0;'></div>";
elseif ( get_row_layout() == 'terms' ) :
// Some other stuff
endif;
具体报错信息为:“Parse error: syntax error, unexpected ':' in...”;并且冒号在替代语法之后是意外的,在该elseif ( get_row_layout() == 'terms' ) :
行中。
知道这里发生了什么吗?
@antoni 建议的答案是不能混合使用替代语法。但在这种情况下,为什么会这样?:
if ( $terms_primcont || $terms_seccont ) : ?>
<div class="terms__body-wrap">
<?php
if ( $terms_primcont ) echo "<div class='terms__primary'>{$terms_primcont}</div>";
if ( $terms_seccont ) echo "<div class='terms__secondary'>{$terms_seccont}</div>";
?>
</div>
<?php endif;