WordPress 模板中使用的嵌套 If else 语句不起作用
Nested If else statements used in a WordPress template isn't working
我不确定下面的嵌套条件有什么问题。即使未设置图像变量(不存在主图像),else 块似乎也永远不会执行。请帮我找出问题所在。
<?php
if ( is_singular() || is_page() ):
if( have_rows('hero') ): while( have_rows('hero') ): the_row();
if( have_rows('hero_-_background_options') ): while( have_rows('hero_-_background_options') ): the_row();
$image = get_sub_field('background_-_image');
if($image):
?>
.default-hero .col .hero-bkg {
display:none;
}
<?php endif; endwhile; endif; endwhile; else: ?>
.default-hero.relative.bg-grey-light {
display: none;
}
<?php endif; endif; ?>
试试这个:else 似乎在错误的地方。
<?php
if ( is_singular() || is_page() ):
if( have_rows('hero') ): while( have_rows('hero') ): the_row();
if( have_rows('hero_-_background_options') ): while( have_rows('hero_-_background_options') ): the_row();
$image = get_sub_field('background_-_image');
if($image):
?>
.default-hero .col .hero-bkg {
display:none;
}
<?php else: ?>
.default-hero.relative.bg-grey-light {
display: none;
}
<?php endif; endwhile; endif; endwhile; endif; endif; ?>
我不确定下面的嵌套条件有什么问题。即使未设置图像变量(不存在主图像),else 块似乎也永远不会执行。请帮我找出问题所在。
<?php
if ( is_singular() || is_page() ):
if( have_rows('hero') ): while( have_rows('hero') ): the_row();
if( have_rows('hero_-_background_options') ): while( have_rows('hero_-_background_options') ): the_row();
$image = get_sub_field('background_-_image');
if($image):
?>
.default-hero .col .hero-bkg {
display:none;
}
<?php endif; endwhile; endif; endwhile; else: ?>
.default-hero.relative.bg-grey-light {
display: none;
}
<?php endif; endif; ?>
试试这个:else 似乎在错误的地方。
<?php
if ( is_singular() || is_page() ):
if( have_rows('hero') ): while( have_rows('hero') ): the_row();
if( have_rows('hero_-_background_options') ): while( have_rows('hero_-_background_options') ): the_row();
$image = get_sub_field('background_-_image');
if($image):
?>
.default-hero .col .hero-bkg {
display:none;
}
<?php else: ?>
.default-hero.relative.bg-grey-light {
display: none;
}
<?php endif; endwhile; endif; endwhile; endif; endif; ?>