duanchi5078 2012-10-07 02:56
浏览 35
已采纳

高级自定义字段 - 未找到sub_field

I'm new to Wordpress and PHP so not sure how to word this problem.

I'm developing a Wordpress blog with custom pages (2 column layout for the pages) and I'm using Advanced Custom Fields.

Anyways so I have a custom field called content_row which has a sub_field named row and that has 2 sub_fields named left_column and right_column.

For some reason I'm not able to pull the row content :(

My page.php code (on the first echo I'm getting a "bool(false)" on the screen):

<?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(); ?>

Any ideas / thoughts? Let me know if you guys need to see more code... some screenshots below: enter image description hereenter image description here

  • 写回答

1条回答 默认 最新

  • donglu9134 2012-10-07 19:52
    关注

    Got it figured out!

    <?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; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?