Some posts skipped
-
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.[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(); ?>’
- The topic ‘Some posts skipped’ is closed to new replies.