【问题标题】:Content is getting displayed endlessly when trying to loop尝试循环播放时,内容会无休止地显示
【发布时间】:2016-03-17 12:54:22
【问题描述】:

我想在查询中循环查询。

这实际上应该成功:

<div class="container inner-cont">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div class="row">
            <div class="col-md-8 column">
                <?php the_content(); ?>
            </div>
            <div class="col-md-4">

                <!-- START -->
                <?php 
                    query_posts(array( 
                        'post_type' => 'mitarbeiter',
                        'showposts' => 10 
                    ) );

                    // Get the members 
                    while (have_posts()) : the_post();
                        if (in_array($title, get_field('kompetenzen'))) :
                            // Display the image
                            $image = get_field('portraitfoto');
                            if (!empty($image)): ?>
                                <img class="sidebar-img" src="<?= $image['url']; ?>" alt="<?= $image['alt']; ?>" /><br />
                            <?php endif; ?>

                            <h2><?php the_title(); ?></h2>
                            <?= the_field('funktion'); ?><br>
                            <?= the_field('telefon'); ?><br>
                            <?= the_field('email'); ?><br>
                        <?php endif; ?>
                    <?php endwhile; ?>
                <!-- END -->

            </div>
        </div>


        <?php endwhile; else: ?>
    <?php endif; ?>
</div>

我遇到的问题是,您在&lt;!-- START --&gt;&lt;!--END --&gt; 之间找到的循环无休止地运行!相同的内容会一遍又一遍地显示。为什么会发生这种情况,我该如何解决?

【问题讨论】:

    标签: php wordpress loops while-loop


    【解决方案1】:

    第二个查询结束后,您必须重置查询。

    <?php wp_reset_query(); ?>
    

    此代码将被重置查询。

    【讨论】:

    • 谢谢,这正是我需要的!!
    猜你喜欢
    • 2022-07-23
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    相关资源
    最近更新 更多