the_field 在 wordpress 中不输出 html 取决于页面的顺序

the_field in wordpress not outputting in html depending on the order of pages

我有一些我无法理解的东西。我在 wordpress 中做了一个单页布局网站。它由一个只有一个mainContainerdiv的template-index.php和大约6个include_once template-组成。然后在 wordpress 的管理部分,我使用高级自定义字段来创建与模板相关的不同字段-index.php.

除了最后一帧或最后包含的文本(如果您愿意的话)以外,一切都很好。但奇怪的是。如果我更改最后两个包含的顺序,两个文本都显示得很好,然后当我更改顺序时,最后一个包含再次松散它的文本。

我检查了代码,每个 php 标签都关闭了就好了,之前的 include 也是。我不知道。你们中有人发生过这样的事情吗?可能是什么?

谢谢

编辑: 这是一些代码。 所以索引页很简单:

<?php
 /* Template Name:  index template */ 
?>

<?php get_header(); ?>
<div class="mainContainer"id='fullpage'>

    <?php include_once 'template-about.php'; ?>
    <?php include_once 'template-theDesign.php'; ?>
    <?php include_once 'template-theApp.php'; ?>
    <?php include_once 'template-getApp.php'; ?>
    <?php include_once 'template-community.php'; ?>
    <?php include_once 'template-contact.php'; ?>

</div>
<?php get_footer(); ?>enter code here

最后两个包含如下所示:

<?php
 /* Template Name: Bob community template */ 
?>
<!-- <div id="section-5"> -->
<div class="sectionContainer community section" id='section_five'>
 <div class="container main">
    <div class="vertical100 firstSection col-md-12 topSection ">
        <section class='worldMap animation col-md-6'>
            <div class="imgContainer">
                <div class="wordpressImg">
                    <img class='worldMap' src="<?php echo get_template_directory_uri(); ?>/img/worldmap.png" />
                </div> <!-- wordpressImg -->
            </div><!-- imgContainer -->
        </section>
        <section class="explications col-md-6">
            <div class="communityExplication">
                    <div class="wordpressTexte">
                        <?php the_field('community_text'); ?>  
                        <div class="stories">
                            <?php 
                                $args = array( 'post_type' => 'stories', 'posts_per_page' => 8, 'orderby' => 'rand' );
                                $loop = new WP_Query($args);
                                $posts = $loop->posts;

                                if(have_posts()) {  
                                    $first = true; ?> 
                                <div class="storieAligner">
                                    <div class="stories-container "> 
                                        <?php
                                        $count = 0;
                                        while($loop->have_posts() ) : $loop->the_post(); 
                                            $randomPost = $posts[$count];
                                            $image = get_field('images');
                                            $temoignage = get_field('temoignage');
                                        ?>              
                                            <!-- <div class="storiePhoto"> -->
                                            <div class='storiesThumbs' style='background-image: url("<?php echo $image['url'];  ?>")'  data-temoignage="<?php echo $temoignage; ?>"></div>
                                                <div class="categorie"></div>
                                            <!-- </div>  -->

                                        <?php $count++; endwhile; ?>
                                    </div> <!-- stories-container -->
                                    <div class="fullStorie hiddenStorie">
                                        <div class="back"></div>
                                        <div class="leftDiv">
                                            <div class="leftContent">

                                            </div>
                                        </div>
                                        <div class="rightDiv">
                                            <div class="rightContent"></div>
                                        </div>
                                    </div> 
                                </div> <!-- storieAligner -->
                            <?php }; ?> <!-- if have_posts -->  

                        </div> <!-- stories -->
                        <div class="linkContainer" ><a class='formToggle pinkButton roll' href="#" title="Wha you say"><span data-title='What you say'>What you say</span></a></div>

                    </div> <!-- wordpressTexte -->
            </div> <!-- commnunityExplication -->
            <!-- <div class="storiesFormContainer"> -->
                <div class="storiesForm hidden">
                    <div class="formContainer">
                        <h1><?php echo __('Leave a Review of your app ', 'site'); ?></h1>
                        <?php echo do_shortcode('[contact-form-7 id="89" title="community-contact"]'); ?>

                    </div>
                </div>
            <!-- </div> storiesFormContainer -->
        </section>
    </div> <!-- get app -->
</div> <!-- main -->

和这样的联系人模板

<?php
 /* Template Name: Contact-us template */ 
?>
<!-- section-6 -->
<div class="sectionContainer contact section" id='section_six'>
  <div class="container main" >
    <div class="vertical100 col-md-12 topSection ">
        <section class='explications col-md-3'>
            <div class="blockTexte">
                <div class="wordpressTexte">
                    <?php the_field('questions'); ?>
                    <a class ='pinkButton roll' href="#" title="visit page"><span data-title='<?php echo __('visit page', 'site'); ?>'><?php echo __('visit page', 'site'); ?></span></a>
                </div>
            </div>
        </section>
        <section class="formulaire col-md-9">
            <div class="formContainer">
                <div class="wordpressForm">
                    <?php echo do_shortcode('[contact-form-7 id="44" title="contact-us"]'); ?>
                </div>
            </div>
        </section>
    </div> <!-- knowBob -->
</div>

那有什么问题吗? P.s。我知道代码中有一点法语和英语。我通常会先想到什么就写什么。

在完成自定义查询循环后,您需要使用 wp_reset_postdata 将 post 数据重置为原始查询:

 <div class="stories-container "> 
 <?php
     $count = 0;
     while($loop->have_posts() ) : $loop->the_post(); 
         $randomPost = $posts[$count];
         $image = get_field('images');
         $temoignage = get_field('temoignage');
 ?>              
 <!-- <div class="storiePhoto"> -->
      <div class='storiesThumbs' style='background-image: url("<?php echo $image['url'];  ?>")'  data-temoignage="<?php echo $temoignage; ?>"></div>
      <div class="categorie"></div>
 <!-- </div>  -->

 <?php $count++; endwhile; wp_reset_postdata(); ?><!-- this line here -->
 </div> <!-- stories-container -->

否则,$post 对象将保留 $loop 查询的最后一个 post,导致任何其他幕后对 post 数据的请求(在你的情况 get_field) 引用错误 post 直到你再次进入外循环。