Wordpress分页在搜索结果中不起作用



我有这个search.php,里面有我按年份/流派搜索的结果:

<?php get_header();
$loop             = new TOROFLIX_Movies();
$sidebar_position = $loop->sidebar_position('sidebar_type_category'); ?>
<div class="Body">
<div class="Main Container">
<?php get_template_part('public/partials/template/letters'); ?>
<div class="TpRwCont <?php echo $sidebar_position; ?>">
<main>
<section>
<div class="Top AAIco-movie_filter">
<h2 class="Title">
<?php if(isset($_GET['genre']) or isset($_GET['years'])){
echo 'Afisez ce doreste sufletul tau! :)';
} else {
echo get_search_query();
} ?>
</h2>
</div>
<ul class="MovieList Rows AX A04 B03 C20 D03 E20 Alt">
<?php if(isset($_GET['genre']) or isset($_GET['years'])){ ?>
<?php $args = array(
'post_type'           => array('movies', 'series'),
'posts_per_page'      => get_option( 'posts_per_page' ),
'post_status'         => 'publish',
'no_found_rows'       => true,
'ignore_sticky_posts' => true,
); 
if( isset( $_GET['genre'] ) && $_GET['genre'] != '' ){
$args['tax_query'][] = array(
'taxonomy' => 'category',
'field'    => 'term_id',
'terms'    => $_GET['genre']
);
}
if( isset( $_GET['years'] ) && $_GET['years'] != '' ){
$args['tax_query'][] = array(
'taxonomy' => 'annee',
'field'    => 'term_id',
'terms'    => $_GET['years']
);
}
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
get_template_part("public/partials/template/loop-principal");
endwhile;
endif; wp_reset_query(); ?>
<?php } else{
if(have_posts()) : 
while(have_posts()) : the_post();
get_template_part("public/partials/template/loop-principal");
endwhile; ?> 
<?php else: ?>
<div>
<?php _e('There are no articles', 'toroflix'); ?>
</div>
<?php endif;
} ?>
</ul>

</section>                
</main>
<?php if($sidebar_position != 'NoSdbr'){ get_sidebar(); } ?>
</div>
</div>
</div>
<?php get_footer(); ?>

的设置

'posts_per_page'      => get_option( 'posts_per_page' ),

在wordpress中显示200个结果。我希望这些结果被分页,假设每页20个帖子,然后下一个,下一个。。在页面内部,结果页面没有其他链接。

我试着添加

<nav class="wp-pagenavi">
<?php echo TOROFLIX_Add_Theme_Support::toroflix_pagination(); ?>
</nav>

,这是我从Category页面上得到的代码,在那里分页工作没有问题,但在搜索结果中不显示任何与分页相关的内容。类别页面代码为:

<?php get_header();
$loop             = new TOROFLIX_Movies();
$sidebar_position = $loop->sidebar_position('sidebar_type_category'); ?>
<div class="Body">
<div class="Main Container">
<?php $alphabet = get_option('alphabet_show');
if($alphabet){
get_template_part('public/partials/template/letters');
} ?>
<div class="TpRwCont <?php echo $sidebar_position; ?>">
<main>
<section>
<div class="Top AAIco-movie_filter">
<h2 class="Title"><?php single_cat_title(); ?></h2>
</div>
<ul class="MovieList Rows AX A04 B03 C20 D03 E20 Alt">
<?php if(have_posts()) : 
while(have_posts()) : the_post();?>
<?php get_template_part("public/partials/template/loop-principal"); ?>
<?php endwhile; ?> 
<?php else: ?>
<div>
<?php _e('There are no articles', 'toroflix'); ?>
</div>
<?php endif; ?>
</ul>
<nav class="wp-pagenavi">
<?php echo TOROFLIX_Add_Theme_Support::toroflix_pagination(); ?>
</nav>
</section>                
</main>
<?php if($sidebar_position != 'NoSdbr'){ get_sidebar(); } ?>
</div>
</div>
</div>
<?php get_footer(); ?>

并且类别的导航工作得很好,我如何才能在搜索页面上获得相同的结果?

我不熟悉Trolofix函数,但您是否尝试过使用默认的WP

the_posts_pagination()

https://developer.wordpress.org/reference/functions/the_posts_pagination/或

paginate_links()

https://developer.wordpress.org/reference/functions/paginate_links/

还要试着弄清楚OROFLIX_Add_Theme_Support::toroflix_pagination()是干什么的?

这可能会为您提供如何在search.php文件上添加自己的分页的线索

最新更新