ACF中继器字段显示在<li> </li>之外

时间:2016-01-27 15:11:04

标签: php wordpress html-lists advanced-custom-fields

我创建了一个自定义小部件,我在其中调用了一些ACF项目。我已经回显了所有自定义字段并且它们工作正常但是出于某种原因,当我查看源代码时,我的转发器字段项目显示在<li>之外?知道我的代码出错了吗?

    if( get_field('background') ):
    echo "<p class='contact-title'>Background/Experience</p>";
        echo "<ul>";
            while( have_rows('background') ): the_row();
            echo "<li>". the_sub_field('licences__permits__etc'). "</li>";
            endwhile;
        echo "</ul>";
    endif;

它输出这个

<p class="contact-title">Background/Experience</p>    
<ul>
    Babysitter
    <li></li>
    Driver's Permit
    <li></li>
    OG loc
    <li></li>
</ul>

1 个答案:

答案 0 :(得分:0)

the_field()函数回显内容。如果要将<li>与返回值连接,则必须使用get_sub_field() - 它只返回值。所以

echo "<li>". get_sub_field('licences__permits__etc'). "</li>";

echo "<li>";
the_sub_field('licences__permits__etc');
echo "</li>"