【问题标题】:Advanced Custom Fields - not finding sub_field高级自定义字段 - 找不到 sub_field
【发布时间】:2012-09-27 18:15:23
【问题描述】:

我是 Wordpress 和 PHP 的新手,所以不知道如何描述这个问题。

我正在开发一个带有自定义页面的 Wordpress 博客(页面的 2 列布局),我正在使用 Advanced Custom Fields

无论如何,我有一个名为 content_row 的自定义字段,它有一个名为 row 的子字段,并且有 2 个名为 left_column 和 right_column 的子字段。

由于某种原因,我无法提取行内容:(

我的 page.php 代码(在第一次回显时,我在屏幕上看到“bool(false)”):

<?php get_header(); ?>

<section style="margin-top:400px;">

<?php 
if( get_field('content_row') ): ?>

    <?php echo var_dump(has_sub_field('row')); ?>

    <?php while( has_sub_field('row') ): ?>

        <?php echo "test"; ?>

    <?php endwhile; ?>

<?php endif; ?>

</section>

<?php get_footer(); ?>

有什么想法/想法吗?让我知道你们是否需要查看更多代码...下面的一些屏幕截图:

【问题讨论】:

    标签: php wordpress custom-fields


    【解决方案1】:

    想通了!

    <?php while(the_flexible_field("row")): ?>
    
    <?php if(get_row_layout() == "2_column"): // layout: Content ?>
    
        <div class="content">
            <?php the_sub_field("left_column"); ?>
            <?php the_sub_field("right_column"); ?>
        </div>
    
    
    
        </div>
    
    <?php endif; ?>
    

    【讨论】:

      猜你喜欢
      • 2016-01-15
      • 2017-12-16
      • 2018-07-11
      • 2013-07-14
      • 2017-08-28
      • 2018-08-06
      • 2013-11-25
      • 2012-08-10
      • 2019-11-07
      相关资源
      最近更新 更多