2015-11-01 40 views
0

我正在開發靈活的內容與wordpress acf自定義字段。我想讓一些靈活的內容出現,所以我使用我在acf網站上找到的代碼。 然後我創建了acf上的字段,但沒有出現。ACF靈活的內容 - 基本文本字段

• Here is what I made on acf : the name of the fexible content
• and here are the sub fields

這僅僅是文本區域和正常texte標題

•這裏是我的代碼

<?php /* Template Name: ateliers */ ?> 


<?php get_header(); ?> 






<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?> 

<?php 

// check if the flexible content field has rows of data 
if(have_rows('ateliers')): 

    // loop through the rows of data 
    while (have_rows('atelieratelier')) : the_row(); 

     if(get_row_layout() == 'content'): 

      the_sub_field('atelier_01'); 


     elseif(get_row_layout() == 'content'): 

      the_sub_field('texte_atelier'); 

     endif; 

    endwhile; 

else : 

    // no layouts found 

endif; 

?> 

<?php endwhile; ?> 

<?php get_sidebar(); ?> 
<?php get_footer(); ?> 

</div> 
</body> 
</html> 

感謝您的幫助

+0

'if(get_row_layout()=='content'):'不存在。這應該等於您爲靈活的內容類型提供的名稱。在你的情況下'atelieratelier'。看起來你只有一個行佈局類型。 – Aibrean

+0

@Aibrean:謝謝!我搜索了幾個小時,但它很簡單。很難找到這樣的信息:什麼是「行」,什麼是「字段」,什麼是「佈局」。謝謝。 – Yagayente

回答

0

,我要繼續前進及寫一個正確的答案...

行:ateliers

場:atelier_01texte_atelier

佈局:atelieratelier

你如果/當應該都是行。

<?php if (have_rows('ateliers')){ ?> 
    <?php while (have_rows('ateliers')) { the_row(); ?> 
    <!--start the row layout--> 
     <?php if (get_row_layout() == 'atelieratelier') { ?> 
     <?php the_sub_field('atelier_01')?> 
     <?php the_sub_field('texte_atelier')?> 
     <?php }?> <!--if you had more layouts you would do an elseif or migrate to a switch statement--> 
     <!--end the row layout--> 
    <?php } // while ?> 
    <?php } ?>