Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Nerina-01 on "previous_posts_link not showing on page 2 while next_posts_link is."

$
0
0

I have a Static page set as front_page and I use a WP_Query the page template includes to display posts. I have a template part product-list.php and in it I have the following:

$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$query = new WP_Query( array( 'paged' => $paged ) );
	$products_args = array (
		'post_type' => 'bb_product',
		'posts_per_page' => 3,
		'paged' => $paged
	);

And then after the $products_query loop:

<?php if ( $products_query->max_num_pages > 1 ) : ?>
    <div class="navigation">
        <?php
        // Bring $wp_query into the scope of the function
        global $wp_query;
        // Backup the original property value
        $backup_page_total = $wp_query->max_num_pages;
        // Copy the custom query property to the $wp_query object
        $wp_query->max_num_pages = $products_query->max_num_pages;
        ?>
        <div class="alignright"><?php next_posts_link('Next Entries'); ?></div>
        <div class="alignleft"><?php previous_posts_link('Previous Entries'); ?></div>
        <?php
        // Finally restore the $wp_query property to it's original value
        $wp_query->max_num_pages = $backup_page_total;
        ?>
    </div>
<?php endif; ?>

The problem is that when I am on page 1, I can see the next_posts_link, but when I am on page 2 there is still only the next_posts_link and no previous_posts_link (the HTML markup is there, but the link is missing). Even when I'm on the last page, there is only the next_posts_link (although there are no next posts) and no previous_posts_link.

I've read many threads with similar/same problems, but I can't solve it. This post helped me to show the navigation at all, before both links where missing.

My test site is here, to see it scroll down, the pagination has a red background.

Can somebody help or point me in the right direction?

Thank you.


Viewing all articles
Browse latest Browse all 8245

Trending Articles