If you are going to paginate the query in future, I recommend the following
-
Changing to
WP_Query
instead as it is better suited for paginated queries. -
Although you still have less than 5 posts, you can make your query pagination ready by adding the
paged
parameter to your query -
Your use of
wp_reset_query()
is incorrect. That is used in conjuction withquery_posts
which you should never use. You should be usingwp_reset_postdata()
. Also, you don’t need to reset the main query, it is already done. -
Just a tip, use curlies instead of
:
andendif
andendwhile
. It is easier to debug and almost all if not all code editors support this syntax
You can try something like this
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
the_content(); ?>
<div class="line2"></div>
<?php }
}
?>
<!-- Start latest post -->
<?php
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$latest_post = new WP_Query( 'numberposts=5&paged=' . $paged ); // Defaults args fetch posts starting with the most recent
if ( $latest_post->have_posts() ) {
while ( $latest_post->have_posts() ) {
$latest_post->the_post(); ?>
<div class="newsthumb">
<a href="https://wordpress.stackexchange.com/questions/180858/<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
</div>
<div class="newstitle">
<a href="https://wordpress.stackexchange.com/questions/180858/<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
<div class="postdate-category">
<?php esportsheaven_posted_on(); ?> | <?php the_category(); ?>
</div>
<div class="newscontent">
<?php the_excerpt(); ?>
</div>
<?php
}
wp_reset_postdata();
}