我使用wordpress 4.0并且我已经成功创建了自定义搜索页面模板,但问题是接下来的分页链接将无法找到我应该做什么请指导我....
这是我的代码
<div class="blog-post">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('post_type' => 'post', 'posts_per_page' => 3, 'ignore_sticky_posts' => 1, 'paged' => $paged );
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- pagination here -->
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="blog-span"><?php /* Start the Loop */ ?>
<?php get_template_part( 'content-search', get_post_format() ); ?>
<div class="space-sep20"></div>
</div>
<?php endwhile; ?>
<div class="nav-previous alignleft my-link"><?php previous_posts_link('« Previous');?></div>
<div class="nav-next alignright my-link"><?php next_posts_link( 'Next »', $the_query->max_num_pages ); ?></div>
<?php else : ?>
<div class="blog-span">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'weblizar' ); ?></h1>
</header>
<div class="entry-content">
<p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'weblizar' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</div>
<?php endif; ?>
</div>
答案 0 :(得分:0)
保留搜索页面结果和分页
<?php
global $query_string;
$query_args = explode("&", $query_string);
$search_query = array();
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
$search_query[$query_split[0]] = urldecode($query_split[1]);
} // foreach
$search = new WP_Query($search_query);
?>
如需更多帮助,请参阅此链接 Create search template
和serch这个标题“保存搜索页面结果和分页”