• Hi everyone,
    I’ve recently come across a problem while developing a wordpress website for a client. He wants posts on first page to display in calendar-like grid. Also, posts must be from only one category. Everything was working fine until yesterday, when I added one post in different category and instead of calendar I received a staircase-like post list.

    However, I maneged to fix it, but now found another bug. I’ve got posts published every day since 15.09, one on each day.
    Everything is ok on the first page, but when I go to the second page, there are 3 posts skipped.

    Screenshots:
    Page 1
    Page 2

    [If you look at my screenshots, there are three posts skipped before the top-right one -thursday-, that’s why the grid is not working properly. I generate my posts from right to left, so there should be one for sunday in top-right corner, than saturday and friday, just like in the row below]

    Here’s the code for my index.php:

    ‘<?php get_header();?>
    <div id=”container” class=”container”>

    <div id=”content” class=”frontpage content”>

    <?php
    $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    $recent_args = array(
    ‘numberposts’ => 1,
    ‘category’ => ‘4’,
    ‘post_status’ => ‘publish’,
    );
    $post_count = 0;
    $recent_posts = wp_get_recent_posts( $recent_args, ARRAY_A );
    $recent_date = get_the_date(‘N’ , $recent_posts[0][“ID”]);
    if($paged == ‘1’){
    $per_page = get_option(‘posts_per_page’) – 7 + $recent_date;
    }
    else{
    $per_page = get_option(‘posts_per_page’);
    }
    $args= array(
    ‘posts_per_page’ => $per_page,
    ‘category_name’ => ‘home’,
    ‘paged’ => $paged
    );
    $home_query = new Wp_Query($args);

    ?>
    <?php if($home_query -> have_posts()){?>
    <div id=”calendar” class=”calendar” style=”direction:rtl;”>

    <?php while ( $home_query ->have_posts() ) : $home_query ->the_post()?>
    <?php
    if($post_count == 0 && $paged == 1){
    get_template_part( ‘home-first’);
    }else{
    get_template_part( ‘content’);
    }
    $post_count ++;
    ?>
    <?php endwhile; ?>
    </div><!– END #calendar –>
    <?php } ?> <!– END if have_posts –>
    <?php wp_reset_postdata(); ?>

    <?php $total_pages = $home_query->max_num_pages; if ( $total_pages > 1 ) { ?>
    <div id=”nav-below” class=”navigation”>
    <span id = “next-page”><?php next_posts_link(__( ‘MORE…’ )) ?></span>
    <span id = “prev-page”><?php previous_posts_link(__( ‘Zobacz mniej…’)) ?></span>
    </div><!– #nav-below –>
    <?php } ?>

    </div><!– #content –>

    <?php get_sidebar(); ?>

    </div><!– #container –>

    <?php get_footer(); ?>’

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jedliczosnek

    (@jedliczosnek)

    Well, I guess I;ve found the problem I’m facing, but still don’t know how to solve it. I set the “posts_per_page” parameter that is different on first page of paginated content that on every other page.
    So, if I have set 28 posts per page by default, but display only 22 posts on first page (because the newest post is on monday), I get 22 posts on first page. But than, when I go to page 2, wordpress chooses the default amount of posts per page. So I get 28 posts, but, at the same time, WordPress thinks I had 28 posts displayed on the first page, and that’s why it starts displaying posts on second page from the 28th.
    Is there any way to go back in The Loop a certain amount of iterations?

    Thread Starter jedliczosnek

    (@jedliczosnek)

    Umm, it looks like I solved it before anyone responded. All I needed to do was to set “offset” parameter for my query.
    For first page offset is of course 0, for any other page:

    ‘$offset = ($paged – 1) * get_option(‘posts_per_page’) – 7 + $recent_date;’

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Some posts skipped’ is closed to new replies.