You have not made provision for pagination, which is integral for what you want to do. You should go and have a look at how to construct a custom query and how to make use of the pagination parameters in WP_Query
You will also need to go and have a look at next_posts_link
and previous_posts_link
which is used to navigate your pages to the next/previous set of posts. This is very simple navigation links. There are more sophisticated pagination functions out there, it is just a matter of searching with google.
It is important that you know and understand how the next_posts_link
is used in custom queries work, otherwise your pagination won’t work at all
Something like this will do the trick. But you need to go and read the links I’ve provided so that you understand what I’ve had done
<?php
// set the "paged" parameter (use 'page' if the query is on a static front page)
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$allposts_args = array(
'post_type' => 'post',
'order' => 'ASC',
'orderby' => 'date',
'posts_per_page' => 10,
'paged' => $paged
);
$allposts_loop = new WP_Query($allposts_args);
if($allposts_loop->have_posts()):
while($allposts_loop->have_posts()):
$allposts_loop->the_post();
?>
<---YOUR LOOP--->
endwhile;
// next_posts_link() usage with max_num_pages
next_posts_link( 'Older Entries', $allposts_loop->max_num_pages );
previous_posts_link( 'Newer Entries' );
wp_reset_postdata();
endif;
You should also have a look at Debugging WordPress when you are developing a theme. You should first end your while statement before you end your if statement, not the other way around. And wp_reset_postdata();
should be called before your endif
statement