Конструктор страниц с гибким контентом ACF isse

Я пытаюсь создать пользовательский конструктор страниц, используя расширенные настраиваемые поля.

В настоящее время я следую этому руководству:

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 -->

Я что-то упускаю? Я полностью следовал учебнику?


person Community    schedule 02.04.2015    source источник
comment
Ничего не отображается на странице, так как есть ошибка PHP? Верхний и нижний колонтитулы отображаются? Если вы поместите какое-то реальное содержимое в часть else оператора, отличное от комментария PHP, будет ли оно отображаться?   -  person johnnyd23    schedule 03.04.2015
comment
Да, мой верхний и нижний колонтитулы отображаются   -  person    schedule 04.04.2015
comment
А как быть с другим вопросом, раскладки не найдены?   -  person johnnyd23    schedule 06.04.2015


Ответы (1)


Вам нужно быть в цикле wp,... обернуть свой код внутри функции, а затем вызвать его

  <?php while ( have_posts() ) : the_post(); ?>
    <?php the_content(); ?>
    <?php acf_content(); ?>
  <?php endwhile; ?>
person moabi    schedule 03.07.2015