I’m working on project that needs to have WooCommerce implemented, and there is a list of products on main page, using a original theme loop. I managed to display all posts and it’s data, and now I’m encountering problems with themes pagination. It’s working kinda fine – it recognises the number of items (products), calculates number of pages, and works fine for first 3 pages.
Then I found out that I have enough posts (normal blog posts, not Woo products) so the pagination is working fine for first 3 pages – which is number where normal blog post pagination would stop.
How can I fix this, so pagination goes for example to page 5, and not show me 404 error page?
Here’s the loop:
<?php
$args = array(
'posts_per_page' => '4',
'post_type' => 'product',
'paged' => get_query_var('paged')
);
$homepage_query = new WP_Query($args);
?>
<?php //query_posts('posts_per_page=4&paged='.get_query_var('paged')); ?>
<?php if ( have_posts() ) : ?>
<?php while ( $homepage_query->have_posts() ) : $homepage_query->the_post(); ?>
<?php if($style == 'blog_style') { ?>
<div id="blog-style" class="post-box">
<?php get_template_part('content', 'blog'); ?>
</div>
<?php } else { ?>
<div class="post-box proizvod-box grid_4 <?php aero_post_box_class(); ?>">
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
<?php //get_template_part('content', ''); ?>
</div>
<?php } ?>
<?php endwhile; wp_reset_query(); ?>
And here’s the pagenavi function file:
http://jsbin.com/umumeq/1/edit
Try
$homepage_query->have_posts()
instead ofhave_posts()
in yourif
condition.