2016-08-31 53 views
0

我正在使用高級自定義字段。我有一張直接與他們的票,但它需要一段時間。我需要立即解決這個問題。具有靈活內容的ACF直放站

試圖爲用戶添加視頻嵌入或圖像的英雄滑塊重複靈活的內容。我如何恰當地回顯循環中的每一部分? WordPress中的內容輸入沒有出現。容器正在呼應,只是沒有內容。

<?php 
if (have_rows('add_resorts_hero_image_slide', 'option')) { 
    while (have_rows('add_resorts_hero_image_slide', 'option')) { 
     the_row(); 

     $herovideo = the_sub_field('add_resorts_hero_slider_video'); 
     $heroimage = the_sub_field('add_resorts_hero_slider_image'); 
      $heroimgsize = 'hero-image'; 
      $heroimg_array = wp_get_attachment_image_src($heroimage, $heroimgsize); 
      $heroimg_url = $heroimg_array[0]; 


     if (have_rows('choose_resorts_hero_slider_content')) { 
      while (have_rows('choose_resorts_hero_slider_content')) { 
      the_row(); 

       echo '<li class="orbit-slide">'; 

       if(get_row_layout() == 'resorts_slider_video') 

        echo $herovideo; 

       elseif(get_row_layout() == 'resorts_slider_video') 
        echo '<img src="'.$heroimg_url.'" />'; 

       echo '</li>'; 

      } 
     } 
} 

}

+0

上述代碼中的所有內容當前是否正常工作?就像添加echo'圖像'一樣;並回聲'視頻';在if和elseif裏面,做那些工作? – Joe

+0

是的,它是功能性的。問題是我如何使用HTML中的變量來回顯HTML。因此,舉例來說... –

+0

我如何迴應src =「」HTML中的圖像變量? –

回答

0

終於想通了,我需要什麼。希望這個答案可以幫助別人!

<!--ORBIT SLIDE--> 
<?php 
if (have_rows('add_resorts_hero_image_slide', 'option')) { 
    while (have_rows('add_resorts_hero_image_slide', 'option')) { 
     the_row(); 

      if (have_rows('choose_resorts_hero_slider_content')) { 
       while (have_rows('choose_resorts_hero_slider_content')) { 
        the_row(); 

        $herovideo = get_sub_field('add_resorts_hero_slider_video'); 
        $heroimage = get_sub_field('add_resorts_hero_slider_image'); 
        $heroimgsize = 'hero-image'; 
        $heroimg_array = wp_get_attachment_image_src($heroimage, $heroimgsize); 
        $heroimg_url = $heroimg_array[0]; 

        if(get_row_layout() == 'resorts_slider_video') { 

        echo '<li class="video orbit-slide">'; 
        echo '<img class="background" src="http://localhost.com/vail/tier2-hero-placeholder.jpg" />'; 

         echo '<div class="container"> 
           <div class="watermark"></div> 
           <iframe id="heroorbitslider-video" 
             src="'. $herovideo .'" 
             width="100%" 
             frameborder="0" 
             scrolling="no" 
             allowFullscreen="true" 
             allowFullScreen="true" 
             webkitAllowFullScreen="true" 
             mozAllowFullScreen="true"> 
           </iframe> 
          </div>'; 
        echo '</li>'; 
       } 

       elseif(get_row_layout() == 'resorts_slider_image') { 

        echo '<li class="orbit-slide">'; 
         echo '<img class="background "src="'. $heroimg_url .'" />'; 
        echo '</li>'; 
       } 


      } 

     } 

    } 

} 

?> 
<!--END ORBIT SLIDE--> 
0

只需重新發布代碼的相關部分:

if(get_row_layout() == 'resorts_slider_video'){ 
    //Display iFrame Video (this assumes that your field is a URL field.) 
    echo '<iframe src="'.get_sub_field('IFRAME URL FIELD NAME GOES HERE').'"></iframe>'; 
}elseif(get_row_layout() == 'resorts_slider_video'){ 
    //Display Image (this assumes that your field is an image field, being saved as an Image Object, and you want to output a custom image size) 
    $myImage = get_sub_field('IMAGE FIELD NAME GOES HERE'); 
    echo '<img src="'.$myImage['sizes']['CUSTOM IMAGE SIZE NAME'].'" alt="'.$myImage['alt'].'" />'; 
} 
+0

我已將我的代碼編輯到當前的位置。在Wordpress中輸入的內容不會作爲回顯視頻或圖像字段的結果而顯示。 –

+0

將「the_sub_field」調用更改爲「get_sub_field」。 the_sub_field回顯數據,你不希望它這樣做。 – Joe

+0

感謝您的迴應!改變了這一點,依然如此。我已經仔細檢查了字段名稱。嗯... –