Support Forums

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Numbered Pagination

Tagged: 

Viewing 8 posts - 1 through 8 (of 8 total)
  • kiwicreative
    #240140

    Hello,

    I have added some basic code for numbered pagination. It works on the initial page load but disappears once going to the 2nd page. No doubt because results are being loaded with AJAX.

    I’ve see quite a few support topics about this, but every one has the replies marked private so not sure if a viable solution was ever discovered. I’m really hoping you can just reiterate something you provided to someone else in a private reply.

    My code is pretty basic:

    Function (in functions.php)

    // Numbered pagination
    function numbered_pagination() {
    	global $wp_query;
    		$big = 999999999; // need an unlikely integer
    			echo paginate_links( array(
    			'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    			'format' => '?sf_paged=%#%',
    			'current' => max( 1, get_query_var('paged') ),
    			'total' => $wp_query->max_num_pages
    		) );
    }

    Then I’m calling the numbered_pagination() my results template.

    I’m happy to provide any additional info if needed.

    Thanks!

    Trevor Moderator
    #240163

    This code has to be inside the Ajax Container you have defined. Is it?

    kiwicreative
    #240166

    Hi Trevor,

    I’m not sure where I define the ajax container. I copied the default results.php, pasted in an overriding template and made slight modifications to integrate Foundation CSS classes and pull in ACF field values.

    Here’s my results template 475.php

    <?php
    /**
     * Search & Filter Pro 
     *
     * Sample Results Template
     * 
     * @package   Search_Filter
     * @author    Ross Morsali
     * @link      https://searchandfilter.com
     * @copyright 2018 Search & Filter
     * 
     * Note: these templates are not full page templates, rather 
     * just an encaspulation of the your results loop which should
     * be inserted in to other pages by using a shortcode - think 
     * of it as a template part
     * 
     * This template is an absolute base example showing you what
     * you can do, for more customisation see the WordPress docs 
     * and using template tags - 
     * 
     * http://codex.wordpress.org/Template_Tags
     *
     */
    ?>
    
    <?php if ( $query->have_posts() ) : ?>
    
    <div class="grid-x grid-padding-x grid-margin-x resources-results-list">
    		
    	<?php 
    	
    	while ($query->have_posts()) : $query->the_post(); 
    	
    		$resource_link_type = get_field('resource_link_type');
    	
    		if( $resource_link_type == 'internal') :
    	
    			$link_dest = get_field('resource_internal');
    			$link_attr = '';
    	
    		elseif( $resource_link_type == 'external') :
    	
    			$link_dest = get_field('resource_external');
    			$link_attr = ' target="_blank"';
    	
    		elseif( $resource_link_type == 'download') :
    	
    			$link_dest = get_field('resource_download');
    			$link_attr = ' target="_blank" download';
    	
    		endif;
    	
    	?>
    		<div class="small-12 medium-6 large-4 cell">
    			<div class="resource-item">
    				<div class="resource-image text-center">
    					<?php the_post_thumbnail( 'full' ); ?>
    				</div>
    				<h3 class="resource-title"><?php the_title(); ?></h3>
    				<div class="resource-type"><?php the_field('resource_type'); ?></div>
    				<div class="resource-content">
    					<?php the_content(); ?>
    				</div>
    				<div class="resource-link">
    					<a href="<?php echo $link_dest; ?>" class="button"<?php echo $link_attr; ?>><?php the_field('resource_link_text'); ?></a>
    				</div>
    			</div>
    		</div>
    	<?php endwhile; ?>
    		
    </div>
    
    <div class="grid-x grid-padding-x pagination align-center">
        <?php /*
    	<div class="cell shrink nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
    	<div class="cell shrink nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
        */ ?>
        
        <div class="cell shrink">
            <?php numbered_pagination(); ?>
        </div>
        
    </div>
    	
    			
    <?php 
    
    else : 
    
    ?>
    <div class="grid-x grid-padding-x">
    	<div class="small-12 cell">
    		<span>No Results Found</span>
    	</div>
    </div>
    <?php endif; ?>
    Trevor Moderator
    #240288

    Ah, you are using the Shortcode method.

    Try replacing the function name in that code with the actual code you used. On Ajx reload, it is quite possible the function does not exist.

    kiwicreative
    #240292

    I am using the shortcode method, my apologies for not mentioning it in my initial message.

    Unfortunately, I’m getting the same results when I use the code itself rather than the function. It appears just fine on page load, but once I go to a paginated page it disappears. If I reload the page on a paginated page it will appear.

    I also just noticed it disappears when I filter the results too.

    I would send screenshots of my forms setup in the backend but doesn’t look like I can attach images. Please let me know if you need any more details, links or WP Access.

    I appreciate the help!

    Trevor Moderator
    #240301

    Can you try this. Return the code back to how it is in the original results.php file, and install and use the WP-PageNavi plugin?

    kiwicreative
    #240311

    That did the trick. I saw people had been using it to achieve the numbered pagination but I was hoping to do without a plugin. My client already has way too many plugins installed and the site performance is suffering because of it. However, I don’t want to spend a ton of time on this so WP-PageNavi it is!

    Thanks for your help.

    Trevor Moderator
    #240315

    Thanks for getting back to me. I will close this thread for now.

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

The topic ‘Numbered Pagination’ is closed to new replies.