[英]ACF Flexible content - basic text field
i'm working on acf custom fields with flexible content with wordpress. 我正在使用wordpress在具有弹性内容的acf自定义字段上工作。 I'd like to make some flexible content appear, so I use the code I found on acf website.
我想显示一些灵活的内容,因此我使用在acf网站上找到的代码。 Then I create the fields on acf, but nothing appear.
然后,我在acf上创建字段,但是什么也没有出现。
• Here is what I made on acf : the name of the fexible content •这是我在acf上所做的:易变内容的名称
• and here are the sub fields •这是子字段
This is just text area and normal texte title
这只是文本区域和正常的文本标题
• here is my code •这是我的代码
<?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>
Thanks for your help 谢谢你的帮助
I'm going to go ahead and write a proper answer for this one... 我将继续为此写一个正确的答案...
Row: ateliers
行:
ateliers
Field: atelier_01
and texte_atelier
字段:
atelier_01
和texte_atelier
Layout: atelieratelier
布局:
atelieratelier
Your if/while should both be the row. 您的if / while应该都是行。
<?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 } ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.