1

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

1 Answer 1

1

Try $homepage_query->have_posts() instead of have_posts() in your if condition.

4
  • No, same thing as before. But thanks for this!
    – jOpacic
    Nov 8, 2012 at 9:54
  • Your pagenavi code is a nightmare! It's intermingling both $homepage_query and the main query, so no wonder there's conflict - you'd be much better off hooking onto (& overriding) the main query with the parse_query or pre_get_posts hook. Nov 8, 2012 at 9:58
  • Can you please post a short example? Would mean a lot!
    – jOpacic
    Nov 8, 2012 at 10:29
  • That code was written when only blog posts were being displayed, and worked great. But now, problem - as you can see.
    – jOpacic
    Nov 8, 2012 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.