0

I'm currently working on a new WP theme.

I was working on my theme locally and it was working perfectly without any issues.

Since I moved the theme to my dev server, everything has worked except for the main loop on the home page.

My loop works perfectly in archive, date, category, tag, author and search pages which were created directly from the home template. The loop even works on paginated versions of the home page e.g. homeurl.com/page/2.

I have double checked the code and it is the same. If it works locally it should work on my dev server, too.

Here is the code for my loop, it is explained below:

<div class="contents__colone" id="contents__main">
    <?php
    $i = 0;
    if (have_posts()) :
        while(have_posts()) :
            $i++;
            if(($i % 2) == 0) {
                $wp_query->next_post();
            } else if ($page_number == 1 and ($i == 1 || $i == 2 || $i == 3)) {
                $wp_query->next_post();
            } else {
                the_post();
                get_template_part('article_preview');
            }
        endwhile;
    endif;
    $i = 0;
    rewind_posts();
    ?>
</div>

<div class="contents__coltwo">
    <?php
    if (have_posts()) :
        while(have_posts()) :
            $i++;
            if(($i % 2) !== 0) {
                $wp_query->next_post();
            } else if ($page_number == 1 and ($i == 1 || $i == 2 || $i == 3)) {
                $wp_query->next_post();
            } else {
                the_post();
                get_template_part('article_preview');
            }
        endwhile;
    endif;
    $i = 0;
    ?>
</div>

I have a carousel at the top that contains the first three posts. The reason for my unusual loop is that I have two columns which I populate with the page's posts whilst also excluding the carousel posts. So in each column I output every other post.

Again this loop works fine locally, but doesn't on the dev server.

6
  • 1
    It is impossible to answer your question without context. Please file an edit and add your homepage code. Jul 16, 2015 at 10:34
  • Also, check and compare your php versions for what it is worth Jul 16, 2015 at 10:35
  • Added the code. PHP on dev is 5.3.29 and locally I have 5.5.22. Jul 16, 2015 at 11:21
  • 1
    Nothing looks strange in your code. I totally forgot to tell you, turn debug on and check for obvious bugs. You should also upgrade your PHP version. All versions prior to 5.4 is not supported anymore, which means security issues might arise with the use of these EOL'ed versions Jul 16, 2015 at 11:28
  • Figured out that WordPress install on server had limited posts on homepage to 3. Thanks for your help, mate. Jul 16, 2015 at 15:19

1 Answer 1

1

nonsequiter reported in a comment that this issue has been resolved:

Figured out that WordPress install on server had limited posts on homepage to 3.

Your Answer

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

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