我是WordPress的初次登台者。我有一个自定义的WordPress搜索页面,我想添加分页我的循环。
<div class="content active" id="panel1">
<?php
global $paged, $wp_query, $wp;
$args = wp_parse_args($wp->matched_query);
if ( !empty ( $args['paged'] ) && 0 == $paged ) {
$paged = $args['paged'];
}
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('post_type=post&s='.$keyword.'&posts_per_page=5&paged='.$paged.'&cat='.$catSearchID);
//print_r($wp_query);exit();
$current = -1;
$current2 = 0;
$emptyPost2 = 0;
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php endwhile; ?>
</div><!-- END panel1-->
<?php wp_reset_query(); ?>
<?php get_template_part('pagination'); ?>
</div><!-- END tabs-content-->
我的模板分页:
global $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query- >query_vars['paged'] : $current = 1;
$t_pagination = array(
'base' => @add_query_arg('page','%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => false,
'type' => 'plain',
);
if($wp_rewrite->using_permalinks())
$t_pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) )) . 'page/%#%/', 'paged');
if(!empty($wp_query->query_vars['s']))
$t_pagination['add_args'] = array('s'=>get_query_var('s'));
echo '<div class="pagination">' . paginate_links($t_pagination) . '</div>';
我尝试了很多解决方案,但它在第二页404错误中给出了。