ACF灵活内容页面构建器isse

时间:2015-04-02 10:12:11

标签: php wordpress content-management-system advanced-custom-fields

我正在尝试使用高级自定义字段创建自定义页面构建器。

我目前正在关注本教程:

https://leachcreative.com/use-flexible-content-fields-build-themes/

但出于某种原因,当它全部构建时,它不会在我的页面上显示任何内容。

我测试页面上的当前代码是:

    <?php
/*
Template Name: tester page
*/
?>
<!-- Returns the header.php file, which will be saved in the same location as index.php -->
<?php get_header(); ?>
<!-- Returns the header.php file, which will be saved in the same location as index.php -->

<?php

    // check if the flexible content field has rows of data
    if( have_rows('blog_content') ):

         // loop through the rows of data
        while ( have_rows('blog_content') ) : the_row();

            if( get_row_layout() == 'image_title_content' ):

                $title = get_sub_field('title');
                $img = get_sub_field('image');
                $content = get_sub_field('content');
                echo '<img src="'. $img['url'] .'">';
                echo '<h2>' . $title . '</h2>';
                echo $content;
            elseif( get_row_layout() == 'paragraph' ): 
                    $paragraph = get_sub_field('paragraph');
                    echo $paragraph;
            elseif( get_row_layout() == 'title_content' ): 

                    $title = get_sub_field('title');
                    $content = get_sub_field('content');
                    echo '<h2>'. $title . '</h2>';
                    echo $content;

            elseif( get_row_layout() == 'video' ): 
                echo '<div class="embed-container">';
                    $video = get_sub_field('video');
                    echo $video;
                echo '</div>';

            elseif( get_row_layout() == 'quote' ): 

                $quote = get_sub_field('quote');
                echo '<blockquote><p><em>';

                echo $quote;
                echo '</em></p></blockquote>';
            elseif( get_row_layout() == 'title_content_video' ): 
                $title = get_sub_field('title');
                $content = get_sub_field('content');
                echo '<h2>' . $title .'</h2>';
                echo $content;
                echo '<div class="embed-container">';
                    $video = get_sub_field('video');
                    echo $video;
                echo '</div>';

            elseif( get_row_layout() == 'code' ):
                $code_title = get_sub_field('code_title');
                $code_desc = get_sub_field('code_description');
                $code = get_sub_field('code');
                echo '<h2>' . $code_title . '</h2>';
                echo $code_desc;
                echo '<code>' . $code . '</code>';

            endif;

        endwhile;

    else :

        // no layouts found

    endif;

?>
<!-- Returns the footer.php file, which will be saved in the same location as index.php -->
<?php get_footer(); ?>
<!-- Returns the footer.php file, which will be saved in the same location as index.php -->

我错过了什么吗?我完全按照教程进行了操作?

1 个答案:

答案 0 :(得分:0)

你需要进入wp循环,...... 将代码包装在函数中, 然后叫它

  <?php while ( have_posts() ) : the_post(); ?>
    <?php the_content(); ?>
    <?php acf_content(); ?>
  <?php endwhile; ?>