Forums Forums Search & Filter Pro AAJAX Pagination without WP-PageNavi

Tagged: ,

Viewing 8 posts - 1 through 8 (of 8 total)
  • Anonymous
    #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!
    Travis

    Trevor
    #135162

    Curiously, 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
    #135164

    Thanks 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 .  __('&nbsp;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!

    Trevor
    #135184

    Are you able to send me a live link/URL to your search page so I can take a look?

    Anonymous
    #135568
    This reply has been marked as private.
    Trevor
    #135572
    This reply has been marked as private.
    Anonymous
    #135626
    This reply has been marked as private.
    Trevor
    #135653

    Is it possible you can enable the theme editor (Appearance -> Editor), and, was there a reason why you did not use Visual Composer Post Grid together with our VC addon?

Viewing 8 posts - 1 through 8 (of 8 total)