Wordpress搜索结果分页 - 不刷新内容

时间:2010-11-26 20:20:32

标签: wordpress search pagination

我正在尝试为我的wordpress搜索结果添加分页。

我能找到一些有关如何执行此操作的信息 - http://codex.wordpress.org/Function_Reference/paginate_links

但是我遇到了一个我无法解释的问题。

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

我只能在页面上显示前10个结果,即使我点击第4页,页面也会刷新但仍显示原始的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();
?>

2 个答案:

答案 0 :(得分:1)

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

您的代码中可能有2项改进之一:

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

或:https://wordpress.stackexchange.com/questions/4368/authors-list-pagination-result-set-from-wpdb-get-results/4370#4370

(以及http://wordpress.stackexchange.com ................上的更多点击次数)

答案 1 :(得分:0)

我正在搜索完全相同,但找不到任何提供简单模板标签的东西,其语义正确的输出(ul)适用于seo,所以我写了自己的一个:{{3} }