【问题标题】:ACF Flexible Content FieldsACF 灵活内容字段
【发布时间】:2018-05-31 23:48:52
【问题描述】:

我设置了许多灵活的内容字段。

其中一个称为“产品选择器”,另一个称为“产品信息”。

产品选择器使用发布对象功能来拉入选定的产品。

我可以引入默认的 wordpress 部分,例如:

<?php the_post_thumbnail(); ?>

但我无法提取“产品信息”中的值。

这真的可能吗?以下代码摘录:

<?php if( have_rows('content_blocks') ):

    while ( have_rows('content_blocks') ) : the_row();

        if( get_row_layout() == 'product_information' ):

            include("inc/product-information.php");     

        elseif( get_row_layout() == 'products_picker' ):

            include("inc/products-picker.php");

        endif;

    endwhile;

endif; ?>

然后在“产品选择器”中,我使用以下代码:

<?php foreach( $post_objects as $post):  ?>

    <?php setup_postdata($post); ?>

        <div class="product">   

            <?php the_post_thumbnail(); ?>      

            <div class="description">

                    /* Echoing post ID returns correct value */
                    <h1><?php echo $post->ID; ?></h1>

                    /* Does not work */
                    <h1><?php the_sub_field('heading', $post->ID); ?></h1>

                    /* Does not work */
                    <?php the_sub_field('description', $post->ID); ?>

            </div> <!-- .description -->

        </div> <!-- .product-->

<?php endforeach; ?>

<?php wp_reset_postdata(); ?>

我的内容结构可能有误。

也许您不能在灵活内容中调用灵活内容?

但我认为应该可以这样做,因为默认字段如下:

the_post_thumbnail(); 

the_title();

工作。

非常感谢您的所有时间和帮助。

【问题讨论】:

    标签: wordpress advanced-custom-fields


    【解决方案1】:

    您必须为每个帖子对象设置灵活行部分。所以在你设置好你的帖子数据后,复制你的

    if( have_rows('content_blocks') ):
        while ( have_rows('content_blocks') ) : the_row();
    

    每个帖子对象的产品信息字段。

    查看https://www.advancedcustomfields.com/resources/flexible-content/ 和嵌套循环示例。我认为这应该让你更接近一点。

    【讨论】:

    • 哇哦。非常感谢。我显然根本不知道需要什么,也永远不会尝试。今天 Stack Overflow 社区的力量很强大!!!
    • ^有史以来最好的评论。一旦你尝试过,请告诉我,因为我自己没有测试过。
    猜你喜欢
    • 2016-02-01
    • 2013-12-29
    • 2020-07-10
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 2016-04-07
    • 2017-01-07
    • 2016-04-07
    相关资源
    最近更新 更多