2016-08-27 33 views
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;?> 
+1

Ummmmm ...你得到什麼錯誤?請編輯您的問題以包含它。 –

+0

它說這是一個語法錯誤 – lala

+1

它會在我看來像你缺少一個關閉endif爲'if(get_field('static_banner')):'。 –

回答

0

想通了一點點幫助一些朋友

<?php if(get_row_layout() == 'banner_select'): // LAYOUT: BANNER STATIC OR SLIDESHOW LAYOUT ?> 
    <?php if(get_sub_field('banners') == 'static_banner'):?>   
     <section class="banner"> 
      <?php 
      $sbimage = get_sub_field('static_banner_img'); // 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_sub_field('static_banner_img')): ?> 
      <a href="<?php the_sub_field('static_url'); ?>"> 
      <img src="<?php echo $sbimageThumbURL;?>" alt="<?php echo $sbimageAlt; ?>" width="<?php echo $sbimageWidth; ?>" height="<?php echo $sbimageHeight; ?>" /></a> 
     </section> 
    <?php endif;?> 
    <?php elseif(get_sub_field('banners') == 'slideshow_banner'): ?> 
     <section class="banner"> 
      <?php the_sub_field('slideshow_banner_img'); ?> 
     </section> 
    <?php endif;?> 
<?php endif;?>