Forums › Forums › Search & Filter Pro › AAJAX Pagination without WP-PageNavi
Tagged: ajax, pagination
- This topic has 7 replies, 2 voices, and was last updated 7 years, 1 month ago by Trevor.
-
Anonymous(Private) October 6, 2017 at 6:36 pm #135159
Hello,
We’ve used this plugin on a few sites and it has worked great! So thanks for the awesome plugin.
On both of those sites we’ve done the pagination with the WP-PageNavi plugin which is suggested in the default results.php template you provide. My question is, how can I use Search And Filter with native WP pagination?
Right now I have a site that uses the Search And Filter and uses AJAX refresh. When I click the numbers in the pagination, the results refresh properly, but the pagination styles don’t change to reflect that. The current page number doesn’t change, and the previous page link does not show up. Additionally, clicking the next page link works the first time, but the second time it’s clicked it goes back to the original results (page 1).
Here’s the code I’m using for the pagination inside the results.php file (theme/search-filer/results.php):
<?php // Pagination $total = $query->max_num_pages; // only bother with pagination if we have more than 1 page if ( $total > 1 ) : ?> <nav class="pagination text-center"> <?php // Set up pagination to use later on $big = 999999999; // need an unlikely integer $pagination = paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('sf_paged') ), 'total' => $total, 'type' => 'plain', 'prev_next' => true, 'prev_text' => __('', 'visceral'), 'next_text' => __('', 'visceral') ) ); echo $pagination; ?> </nav> <?php endif; ?>
Any directions for getting this to work without WP-PageNavi?
Thanks!
TravisTrevor(Private) October 6, 2017 at 6:51 pm #135162Curiously, our code IS the standard WP pagination. If you see numbers, it is added by the theme. In any event, you will have an Ajax container defined, and the pagination must be INSIDE that.
For the Shortcode display results method, Search & Filter adds its own container and knows to use that for Ajax.
Our standard results.php should refresh the pagination upon an Ajax refresh, with or without WP-PageNavi.
Anonymous(Private) October 6, 2017 at 7:10 pm #135164Thanks for the quick response! I should have mentioned that I’m using the shortcode method for this S&F implementation, so I don’t have an ajax container defined.
This is the entire results.php template in case that helps:
<?php /** * Search & Filter Pro * * Resource Results Template * * */ if ( $query->have_posts() ) { $total_posts = $query->found_posts; ?> <?php $current_page = $query->query_vars['paged']; $current_post_count = $query->post_count - 1; $posts_per_page = $query->query_vars['posts_per_page']; $total_posts = $query->found_posts; $posts_start = ($current_page - 1 ) * $posts_per_page + 1; if( $posts_per_page > $total_posts ) { $posts_start = 1; } $posts_end = $posts_start + $current_post_count; ?> <div class="search-filter-results-header"> <?php echo $posts_start . "-" . $posts_end . " of " . $total_posts . __(' Resources', 'visceral'); ?> </div> <div class="row resources-list"> <?php while ($query->have_posts()) { $query->the_post(); get_template_part('templates/list-item-resource'); } ?> </div> <?php // Pagination $total = $query->max_num_pages; // only bother with pagination if we have more than 1 page if ( $total > 1 ) : ?> <nav class="pagination text-center"> <?php // Set up pagination to use later on $big = 999999999; // need an unlikely integer $pagination = paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('sf_paged') ), 'total' => $total, 'type' => 'plain', 'prev_next' => true, 'prev_text' => __('', 'visceral'), 'next_text' => __('', 'visceral') ) ); echo $pagination; ?> </nav> <?php endif; ?> <?php } else { echo "No Results Found"; } ?>
Thank you!
-
AuthorPosts