我想在不同页面上显示不同的幻灯片
我认为我需要使用if else否则php循环,但不能正确获取语法
这是我的代码:
<?php if( is_front_page() ) : ?>
<div class="mobile-header"> <img src="/images/mobile-header.jpg" width="1080" height="1000" alt="Sean Sheehan" /> </div>
<?php if ( function_exists( 'soliloquy' ) ) { soliloquy( 'homepage-dark', 'slug' ); } ?>
<?php else : ?>
<header id="masthead" class="<?php echo is_singular() && twentynineteen_can_show_post_thumbnail() ? 'site-header featured-image' : 'site-header'; ?>">
每当我尝试添加Alse时,代码断开。我尝试了这一点以显示页面ID 25:
的其他滑块。 <?php if( is_front_page() ) : ?>
<div class="mobile-header"> <img src="/images/mobile-header.jpg" width="1080" height="1000" alt="Sean Sheehan" /> </div>
<?php if ( function_exists( 'soliloquy' ) ) { soliloquy( 'homepage-dark', 'slug' ); } ?>
<?php elseif ( is_page(25) ) {
?>
<div class="mobile-header"> <img src="/images/mobile-header.jpg" width="1080" height="1000" alt="Sean Sheehan" /> </div>
<?php if ( function_exists( 'soliloquy' ) ) { soliloquy( 'photography-dark', 'slug' ); } ?>
<?php else : ?>
<header id="masthead" class="<?php echo is_singular() && twentynineteen_can_show_post_thumbnail() ? 'site-header featured-image' : 'site-header'; ?>">
但此代码不正确。
主要问题是:
-
虽然您可以将
{}
或:
结构用于if
语句,但您不能在同一控制块中使用 mix 它们(此处详细介绍(。由于您从if():
开始,因此无法在<?php elseif ( is_page(25) ) {
中使用elsif() {
。您需要使用格式elsif():
,因此该行需要像这样读取 -<?php elseif ( is_page(25) ):
-
您需要用
endif;
关闭块
因此,校正的代码(请参见下面的评论(看起来像:
<?php if( is_front_page() ) : ?>
<div class="mobile-header"> <img src="/images/mobile-header.jpg" width="1080" height="1000" alt="Sean Sheehan" /> </div>
<?php if ( function_exists( 'soliloquy' ) ) { soliloquy( 'homepage-dark', 'slug' ); } ?>
<!-- elseif(): not { -->
<?php elseif ( is_page(25) ):?>
<div class="mobile-header"> <img src="/images/mobile-header.jpg" width="1080" height="1000" alt="Sean Sheehan" /> </div>
<?php if ( function_exists( 'soliloquy' ) ) { soliloquy( 'photography-dark', 'slug' ); } ?>
<?php else: ?>
<header id="masthead" class="<?php echo is_singular() && twentynineteen_can_show_post_thumbnail() ? 'site-header featured-image' : 'site-header'; ?>">
<!-- don't forget endif; -->
<?php endif; ?>