【发布时间】:2021-12-19 00:24:50
【问题描述】:
我正在使用 rewind_posts() 函数根据帖子类型对搜索结果进行分组,并将它们显示在相关选项卡下。循环工作得很好,但我正在努力显示no results found 信息。
例如,如果我正在搜索文档,我希望帖子显示在documents 下,但在page 和people 选项卡下我需要回显No results。
<?php
if ( have_posts() ) { ?>
<section class="tabs" id="pages">
<?php while( have_posts() ) { the_post(); ?>
<?php if ( $post->post_type == 'page' ) {
include(locate_template('partials/pages.php', false, false)); ?>
<?php } ?>
<?php
} ?>
</section>
<?php
rewind_posts(); ?>
<section class="tabs" id="people">
<?php while( have_posts() ) { the_post(); ?>
<?php if ( $post->post_type == 'people' ) {
include(locate_template('partials/profile.php', false, false)); ?>
<?php } ?>
<?php
} ?>
</section>
<?php
rewind_posts(); ?>
<section class="tabs" id="documents">
<?php while( have_posts() ) { the_post(); ?>
<?php if ( $post->post_type == 'documents' ) {
include(locate_template('partials/document.php', false, false)); ?>
<?php } ?>
<?php
} ?>
</section>
<?php
rewind_posts(); ?>
</div>
【问题讨论】: