• Resolved TheSteveHimself

    (@thestevehimself)


    Hi,

    I am using the pro version of your plugin and have a problem.
    I have setup a splittest for the frontpage to test different styles for the post listing.

    So I copied the page and applied a different template to the variation.
    This way I also have a different permalink for the variation, which we need for the analytics side of things.

    But now on the variation – the pagination is broken and doesn’t work anymore.

    This is the code i use for pagination:

    php
    <?php
    	$paged = (get_query_var('page')) ? get_query_var('page') : 1;
    
    	$args = array(
    		'post_type' => 'post',
    		'post_status' => 'publish',
    		'posts_per_page' => get_option('posts_per_page'),
    		'page' => $page,
    	);
    	$query = new WP_Query($args);
    
    	if ($query->have_posts()) {
    		while ($query->have_posts()) {
    			$query->the_post();
    			get_template_part('parts/split-tests/frontpage/content', 'list');
    		}
    
    		if ($query->max_num_pages > 1) {
    ?>
    				<nav class="pagination-container">
    					<ul class="pagination">
    						<li class="prev-posts-link">
    							<?php echo get_next_posts_link('See more', $query->max_num_pages); ?>
    						</li>
    						<li class="next-posts-link">
    							<?php echo get_previous_posts_link('Newer Entries'); ?>
    						</li>
    					</ul>
    				</nav>
    <?php
    		}
    	} else {
    		get_template_part('parts/content', 'none');
    	}
    	wp_reset_query();
    ?>
    

    Any info on how to solve this would be greatly appreciated!

    Thanks,
    Steve

    • This topic was modified 7 years, 9 months ago by TheSteveHimself. Reason: fixed codeformatting
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter TheSteveHimself

    (@thestevehimself)

    Nevermind I fixed it ??
    Turns out I didn’t understand how wordpress handles pagination well enough.

    For future reference:
    There are 2 basic mechanics when it comes to pagination.

    1. Pagination on page templates for pages that are set as a static Front Page:
    They use the ‘page’ query var to determine which page should be displayed. So we also need to hand this parameter to the WP_Query call

    2. Pagination on “normal” pages use the ‘paged’ query var to achieve the same.

    So the fix is to just change the WP_Query on the variation template to:

    
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    $args = array(
    	'post_type' => 'post',
    	'post_status' => 'publish',
    	'posts_per_page' => get_option('posts_per_page'),
    	'paged' => $paged,
    );
    $query = new WP_Query($args);
    

    Source: https://codex.www.ads-software.com/Class_Reference/WP_Query#Pagination_Parameters

    Plugin Author Josh Kohlbach

    (@jkohlbach)

    Hey Steve,

    Yep it’s very confusing at first due to the naming convention used. Easy to miss the extra ‘d’!

    In future since you’re a Premium add-on customer feel free to write into support via our site! We can get to you faster than on these forums.

    Cheers,
    Josh

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem with splittest on frontpage and pagination’ is closed to new replies.