1
我是新來ACF和PHP,我得到一個語法錯誤,但我不知道我做錯了什麼。ACF PHP如果其他佈局 - 橫幅/幻燈片
<!--BANNER STATIC OR SLIDESHOW LAYOUT-->
<?php if(get_row_layout() == 'banner'): // layout: Content ?>
<section class="banner">
<?php
$sbimage = get_field('static_banner'); // Array returned by Advanced Custom Fields
$sbimageAlt = $sbimage['alt']; // Grab, from the array, the 'alt'
$sbimageWidth = $sbimage['width']; // Grab, from the array, the 'width'
$sbimageHeight = $sbimage['height']; // Grab, from the array, the 'height'
$sbimageThumbURL = $sbimage['sizes']['large']; //grab from the array, the 'sizes', and from it, the 'thumbnail'
?>
<?php if(get_field('static_banner')): ?>
<a href="<?php the_field('static_url'); ?>">
<img src="<?php echo $sbimageThumbURL;?>" alt="<?php echo $sbimageAlt; ?>" width="<?php echo $sbimageWidth; ?>" height="<?php echo $sbimageHeight; ?>" /></a>
</section>
<?php else: ?>
<section class="banner">
<?php the_field('slideshow_banner'); ?>
</section>
<?php endif; ?>
或者我需要一個while循環嗎?我試圖把它們放在一起,但我也遇到了一些關於此的語法錯誤。
<!--BANNER STATIC OR SLIDESHOW LAYOUT-->
<?php if(get_row_layout() == 'banner_select'): // layout: Content ?>
<?php if(have_rows('banner')): // check if the flexible content field has rows of data ?>
<?php while (have_rows('banner')) : the_row(); // loop through the rows of data?>
<?php if(get_row_layout() == 'static_banner'):?>
<section class="banner">
<?php
$sbimage = get_field('static_banner'); // Array returned by Advanced Custom Fields
$sbimageAlt = $sbimage['alt']; // Grab, from the array, the 'alt'
$sbimageWidth = $sbimage['width']; // Grab, from the array, the 'width'
$sbimageHeight = $sbimage['height']; // Grab, from the array, the 'height'
$sbimageThumbURL = $sbimage['sizes']['large']; //grab from the array, the 'sizes', and from it, the 'thumbnail'
?>
<?php if(get_field('static_banner')): ?>
<a href="<?php the_field('static_url'); ?>">
<img src="<?php echo $sbimageThumbURL;?>" alt="<?php echo $sbimageAlt; ?>" width="<?php echo $sbimageWidth; ?>" height="<?php echo $sbimageHeight; ?>" /></a>
</section>
<?php elseif(get_row_layout() == 'slidshow_banner'): ?>
<section class="banner">
<?php the_field('slideshow_banner'); ?>
</section>
<?php endif;?>
<?php endwhile; ?>
<?php else : // no layouts found ?>
<?php endif;?>
<?php endif;?>
Ummmmm ...你得到什麼錯誤?請編輯您的問題以包含它。 –
它說這是一個語法錯誤 – lala
它會在我看來像你缺少一個關閉endif爲'if(get_field('static_banner')):'。 –