Display All WordPress Posts in One Page with Template Code


While using a plugin to display all posts in one page is the easiest way, some of you may want to learn how to do it with page templates code.

First you will need to create a custom page template and copy the styling from your page.php file.

After that, you will use a loop below to display all posts in one page.

<?php  
 $wpb_all_query = new WP_Query(
  array(
   'post_type'=>'post', 
   'post_status'=>'publish', 
   'posts_per_page'=>-1
  )
 ); 
?>

<?php if ( $wpb_all_query->have_posts() ) : ?>

<ul>

 <!-- the loop -->
 <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
  <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
 <?php endwhile; ?>
 <!-- end of the loop -->

</ul>

 <?php wp_reset_postdata(); ?>

<?php else : ?>
 <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

posts_per_page - Number of post display on the page
-1 - unlimited





Related Post


Latest Post


Recent Posts Widget

Make sure to never miss a thing...

Get the latest news from the creative industry along with other creative goodies, conveniently delivered to social media.