This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Tagged: ,

Add themeblvd pagination

  • Creator
    Topic
  • #20739
    John
    Participant

    if I build my own grid is it possible to incorporate the themeBlvd pagination?

    function pract_grid() {
    	$args = array(
    		'post_type'=> 'practitioner',
    		'meta_key' => 'last_name',
    		'orderby' => array( 'menu_order' => 'DESC', 'meta_value' => 'ASC' ),
    		'posts_per_page' => 15		
    	);
    	$x = new WP_Query($args);
    	echo '<div>';
    	if( $x->have_posts() ) {
    		 while ( $x->have_posts() ) {
    		 	$x->the_post();
    			get_template_part( 'content', 'pract_result' );	
    		} 
    	echo '</div>';
    		
    		themeblvd_pagination();//NEED PAGINATION HERE?
    	
    	}else{ 
    		echo 'no results';
    	}
    	wp_reset_postdata();
    }
    add_action('themeblvd_main_bottom', 'pract_grid');

    thx,
    John

Viewing 8 replies - 1 through 8 (of 8 total)
  • Author
    Replies
  • #20744
    Jason Bobich
    Keymaster

    Try passing in the number of pages to the function.

    themeblvd_pagination( $x->max_num_pages );
    #20746
    John
    Participant

    The expected pagination links are added (including the correctly calculated number of pages for the query), but each page continues to show the first 15 results.

    #20748
    Jason Bobich
    Keymaster

    I think it’s an issue with your query, not the pagination. Because you’re doing a secondary query, you need to check for your paged parameter existing (from the URL of the page), and then adjust your query by using the ‘paged’ parameter.

    #20749
    Jason Bobich
    Keymaster

    A common way people do this is something like this:

    $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
    
    $args = array(
    	'post_type'=> 'practitioner',
    	'meta_key' => 'last_name',
    	'orderby' => array( 'menu_order' => 'DESC', 'meta_value' => 'ASC' ),
    	'posts_per_page' => 15,
    	'paged' => $paged	
    );

    http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

    #20751
    John
    Participant

    Nope, sorry, same result.

    function pract_grid() {
    	$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
    	$args = array(
    		'post_type'=> 'practitioner',
    		'meta_key' => 'last_name',
    		'orderby' => array( 'menu_order' => 'DESC', 'meta_value' => 'ASC' ),
    		'posts_per_page' => 15,
    		'paged' => $paged			
    	);
    	$x = new WP_Query($args);
    	echo '<div>';
    	if( $x->have_posts() ) {
    		 while ( $x->have_posts() ) {
    		 	$x->the_post();
    			get_template_part( 'content', 'pract_result' );	
    		} 
    	echo '</div>';
    		
    		themeblvd_pagination( $x->max_num_pages );
    	
    	}else{ 
    		echo 'no results';
    	}
    	wp_reset_postdata();
    }
    #20752
    Jason Bobich
    Keymaster

    It’s a common topic you can research more about.

    #20753
    John
    Participant

    $paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1; notice the “d” ‘s (no d’s is for static front page?)
    so for anyone following in future:

    function pract_grid() {
    	$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    	$args = array(
    		'post_type'=> 'practitioner',
    		'meta_key' => 'last_name',
    		'orderby' => array( 'menu_order' => 'DESC', 'meta_value' => 'ASC' ),
    		'posts_per_page' => 15,
    		'paged' => $paged			
    	);
    	$x = new WP_Query($args);
    	if( $x->have_posts() ) {
    		echo '<div>';
    		 while ( $x->have_posts() ) {
    		 	$x->the_post();
    			get_template_part( 'content', 'pract_result' );	
    		} 
    		echo '</div>';
    		
    		themeblvd_pagination( $x->max_num_pages );
    	
    	}else{ 
    		echo 'no results';
    	}
    	wp_reset_postdata();
    }

    thanks for the boost Jason

    #20754
    Jason Bobich
    Keymaster

    Yeah, this is the full way I do it to account for different scenarios if you want to dig into the theme:

    $query = array( ... );
    
    if ( get_query_var('paged') ) {
    	$query['paged'] = get_query_var('paged');
    } else if ( get_query_var('page') ) {
    	$query['paged'] = get_query_var('page');
    } else {
    	$query['paged'] = 1;
    }

    … The static frontpage is complicated though. Doing that will not solve it in all cases. In order for theme elements like post grid, post list, etc, to fully work on a static frontpage I filter into pre_get_posts.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.