The single.php page I am working on was able to display two loops successfully, the first being the actual page's post, and the second loop displaying the last 5 posts. However, since I have styled the page things have gone wrong. Now the second loop only ever displays the very last post. When I inspect the backend of the page, it shows that the post page is running every other post from the last 5 posts. For example, if the last 5 posts are 228, 227, 226, 225, and 224, the page is running just 228, 226, and 224. (What happened to 227 and 225?) However, even though 228, 226, and 224 are running, only 228 is showing.
I have checked the Reading section of the site and have it clearly marked to display 5 posts, yet it still won't display anything other than that last post.
Any thoughts?
<div id="blogcontainer">
<?php query_posts('post_type=post') ?>
<?php if (have_posts()) : while(have_posts()) : the_post();?>
<div class="postcontainer" id="post-<?php the_ID(); ?>">
<div class="thumb">
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(array(100,100)); ?>
</a>
<?php endif; ?>
</div>
<div class="topblock"><div class="titleblock">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php
the_title(); ?></a></div>
<div class="moreblock">MORE ></div>
</div>
<div class="block">
<div class="date"><p><span class="date"><?php the_time('F j, Y'); ?></span>
</p></div>
<?php html5wp_excerpt('html5wp_index'); ?>
</div>
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>
</div>
</div>
</div>
Here is the page single post
The single.php page I am working on was able to display two loops successfully, the first being the actual page's post, and the second loop displaying the last 5 posts. However, since I have styled the page things have gone wrong. Now the second loop only ever displays the very last post. When I inspect the backend of the page, it shows that the post page is running every other post from the last 5 posts. For example, if the last 5 posts are 228, 227, 226, 225, and 224, the page is running just 228, 226, and 224. (What happened to 227 and 225?) However, even though 228, 226, and 224 are running, only 228 is showing.
I have checked the Reading section of the site and have it clearly marked to display 5 posts, yet it still won't display anything other than that last post.
Any thoughts?
<div id="blogcontainer">
<?php query_posts('post_type=post') ?>
<?php if (have_posts()) : while(have_posts()) : the_post();?>
<div class="postcontainer" id="post-<?php the_ID(); ?>">
<div class="thumb">
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(array(100,100)); ?>
</a>
<?php endif; ?>
</div>
<div class="topblock"><div class="titleblock">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php
the_title(); ?></a></div>
<div class="moreblock">MORE ></div>
</div>
<div class="block">
<div class="date"><p><span class="date"><?php the_time('F j, Y'); ?></span>
</p></div>
<?php html5wp_excerpt('html5wp_index'); ?>
</div>
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>
</div>
</div>
</div>
Here is the page single post
Share Improve this question edited Nov 29, 2018 at 7:43 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Nov 29, 2018 at 0:37 user5258035user5258035 113 bronze badges 3 |1 Answer
Reset to default 1The answer to the above question was very simple and answered by a kind person at the Wordpress Support forum. There was an extra div that was causing problems. Remove the last div, and it all worked out fine. A very simple solution, but one I wouldn't have known that could cause that much trouble. I hope anyone else looking for a similar solution checks on the divs, because it is very important that the endif statements do not get separated off from their intended function. In this case, the extra div was responsible.
The new code looks like this:
<div id="blogcontainer" onmouseover="RollOff1()" onmouseout="RollOff2()">
<?php query_posts('post_type=post') ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<div class="postcontainer" id="post-<?php the_ID(); ?>">
<div class="thumb">
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(array(100,100)); // Declare pixel size you need
inside the array ?>
</a>
<?php endif; ?>
</div>
<div class="topblock"><div class="titleblock"> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></div>
<div class="moreblock"><a href="<?php the_permalink(); ?>">MORE ></a></div>
</div>
<div class="block">
<div class="date"><p><span class="date"><?php the_time('F j, Y'); ?></span></p>
</div>
<?php html5wp_excerpt('html5wp_index'); ?>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
query_posts
, it overwrites the main query and can produce unexpected results. UseWP_Query
instead. – Milo Commented Nov 29, 2018 at 4:20