2010-11-26 111 views
0

我想添加分页到我的WordPress的搜索结果。WordPress的搜索结果分页 - 不刷新内容

我能够找到关于如何做到这一点的一些信息 - http://codex.wordpress.org/Function_Reference/paginate_links

但我碰到的,我无法解释一个问题。

分页正被添加到搜索结果页面的底部,并且页面数量根据我使用的搜索字词而变化。如果您点击下一个按钮或选择一个页码,网址会更改,但搜索结果不会...

即使点击第4页,我也只能在页面上显示前10个结果,页面将刷新,但仍显示原始的10个结果。

有谁知道我该如何解决这个问题?

这里是我的代码

<?php 
get_header(); 

iinclude_page(608); ?> 

<li id="search"> 
<form id="searchform" method="get" action="<?php bloginfo('home'); ?>"> 
    <div style="text-align:center; margin:20px 0 25px 0;"> 
     <label style="font-weight:bold;" for="s"><?php _e('Search Database:'); ?></label> <input type="text" name="s" id="s" size="20" /> <?php $args = array('hide_empty'=>0,'depth'=>2,'hierarchical'=> 1,); 
wp_dropdown_categories($args); ?> <input type="submit" value="<?php _e('Search'); ?>" /> 
    </div> 
    </form> 
</li> 
<hr /> 
<?php 
if (have_posts()): ?> 
<?php 
while (have_posts()) : the_post(); ?> 
<li class="postWrapper" id="post-<?php the_ID(); ?>"> 

<h3 class="entry-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3> 
<div id="postdata"> 
<div class="search-content"> 
<?php the_excerpt(__('<p>Read More ></p>')); ?> 
</div> 

<div class="entry-meta"> 
<?php 
    $view_in_browser = '<a class="google-viewer" href="http://docs.google.com/viewer?url='.$attachment_url.'">View document in browser</a>'; 
    $download = '<a class="download" href="'.$attachment_url.'">Download PDF</a>'; 
    echo $view_in_browser . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $download; 
?> 
</div> 

</div> 
<hr /> 
</li> 
<?php endwhile; ?> 

<?php 
global $wp_rewrite;   
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1; 

$pagination = array(
    'base' => @add_query_arg('page','%#%'), 
    'format' => '', 
    'total' => $wp_query->max_num_pages, 
    'current' => $current, 
    'show_all' => true, 
    'type' => 'plain', 
    ); 

if($wp_rewrite->using_permalinks()) 
    $pagination['base'] = user_trailingslashit(trailingslashit(remove_query_arg('s',get_pagenum_link(1))) . 'page/%#%/', 'paged'); 

if(!empty($wp_query->query_vars['s'])) 
    $pagination['add_args'] = array('s'=>get_query_var('s')); 

echo paginate_links($pagination);  
?> 

<?php else: ?> 
<h3 style="text-align:center; font-weight:bold; color:#333;"><?php _e('Sorry, no posts matched your criteria.'); ?></h3> 
<p style="text-align:center">Please try Searching anohter term.</p> 
<?php 
endif; 
?> 
<?php if (will_paginate()): ?> 
<?php endif; ?> 
<?php 
get_footer(); 
?> 

回答

1

这可能取决于您的查询,它可能围绕不正确使用寻呼的$(无法看到您的代码)

也许你有2个改进之一

参见:https://wordpress.stackexchange.com/questions/2638/pagination-resolving-to-first-page-only

OR:在你的代码进行https://wordpress.stackexchange.com/questions/4368/authors-list-pagination-result-set-from-wpdb-get-results/4370#4370

(和http://wordpress.stackexchange.com更多的点击................)

+0

感谢您的意见。你认为你可以看看我的代码...我真的不明白我做错了什么,因为我从来没有玩过wp循环。 – Adam 2010-11-26 21:13:27

0

我在搜索一模一样,但无法找到任何东西,提供了一个简单的模板标签与语义正确的输出(ul),适用于seo,所以我写了我自己的:Easy Pagination Deamon