开发者

Wordpress Search Result Pagination - not refreshing content

开发者 https://www.devze.com 2023-01-27 16:35 出处:网络
I\'m trying to add pagination to my wordpress search results. I was able to locate some information on how to do this - http://codex.wordpress.org/Function_Reference/paginate_links

I'm trying to add pagination to my wordpress search results.

I was able to locate some information on how to do this - http://codex.wordpress.org/Function_Reference/paginate_links

But I've run into a problem that I can't explain.

The Pagination is being added to the bottom of the search results page and the number of pages does change depending on what search term I use. If you click the next button or select a page number the url changes but the search results don't...

I'm only able to have the first 10 result appear on the page, even if I click page 4, the page will refresh but it still displaying the original 10 results.

Does anyone know how I could fix this?

Here's my code

<?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();
?>


It probably depends on your query and it probably revolves around not using the $paged correctly (cant see your code)

Probably you have one of the 2 improvement to be made in your code:

See: 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

(and more hits on http://wordpress.stackexchange.com ................)


I was on the search for exactly the same, but couldn't find anything that offered a simple template tag with a semantically correct output (ul) that works well for seo, so i wrote my own one: Easy Pagination Deamon

0

精彩评论

暂无评论...
验证码 换一张
取 消