I have been creating a one page theme for a wordpress site from scratch, and in my local server, it displays all posts related to the sections normally. However, I find sometimes that one post, usually the starting one out each category of posts I have maintained, will not display data. what can be the reason for this effect? Please comment if you need to see an excerpt of the code I have maintained.
Edit:- Here is an excerpt of what I have done in index.php:-
<div id="img_slider" class="row">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
if (in_category(3)){ ?>
<?php the_content(); ?>
<?php } ?>
<?php endwhile; else : ?>
<?php endif; ?>
</div>
<div id="message">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
if (in_category(5)){ ?>
<div class="box">
<?php the_content(); ?>
</div>
<?php } ?>
<?php endwhile; else : ?>
<?php endif; ?>
</div>
<div id="products">
<div class="grey-box" >
<h2>Product List 1</h2>
<div id="products-main">
<div class="row">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post();
//echo '0';
if (in_category(2)){
get_template_part( 'template_parts/product');
}
?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
</div>
</div>
<h2>Product List 2</h2>
<div id="products-other">
<div class="row">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post();
//echo '0';
if (in_category(6)){
get_template_part( 'template_parts/product');
}
?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
I found the answer to my question. The problem was with the number of posts that the loop could handle at a time. If you need to increase or decrease the number of posts the loop can handle per page, add this code BEFORE the loop.
<?php query_posts('posts_per_page=amount'); ?>
<?php //the-loop-goes-here ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.