How to Display All the WordPress Posts on One Page

by Vincy. Last modified on July 13th, 2022.

There are a real possible scenarios wherein you want to display all the WordPress posts on a single page. For example, you might be looking to publish an archive page or a sitemap page where you want to list all the posts without any pagination.

In this article I will detail you a way using which you can list all the WordPress posts on a single page.

When will you need to display all WordPress posts on a page?

  • Archive Page – You can have an archive page where you can list all the posts on a single page as a consolidated list for the users.
  • Sitemap Page – A user readable sitemap page which can have all the posts.
  • Special purpose small sites – Consider an events site built using WordPress and you want to show all the posts (here events) on one page.

How to show all posts on one page?

There are many different ways to achieve this. The most popular being the WordPress way of achieving things using plugins. I generally resort to plugins as the last resort.

First I always try to achieve things using WordPress inbuilt ways, then opt for functions.php custom code way and if still cumbersome, finally I go to the plugin way and work on finalizing the plugins.

Because as you know, for any task the WordPress market is fully loaded with many number of plugins. Nowadays, there is no shortage of plugins, but the real task is to identify the right WordPress plugin.

  • Here in this article, I will not be promoting any WordPress plugins rather, I will present you the custom code way to display all posts on a single page. Let us create a custom page template and use it to display all the posts.

How to create a Custom Page Template and Display all Posts?

The custom page template is one of the simplest ways. It is easier to do as you might have already created custom templates. So, what is a custom page? By default, WordPress gives the option to create posts and pages and this is the standard template that comes default with the WordPress.

When you want to have some custom designed template with a predefined structure, then we can create it as a template and use it for publishing an article. So the content you create will be fitted onto the template as you have designed and published.

Custom Page Template for All Posts on a Single Page

<?php 
// wp-query to get all published posts without pagination
$allPostsWPQuery = new WP_Query(array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>-1)); ?>
 
<?php if ( $allPostsWPQuery->have_posts() ) : ?>
 
<ul>
     <?php while ( $allPostsWPQuery->have_posts() ) : $allPostsWPQuery->the_post(); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
</ul>
     <?php wp_reset_postdata(); ?>
 <?php else : ?>
    <p><?php _e( 'There no posts to display.' ); ?></p>
<?php endif; ?>

First, we define a WP query to get all the published posts without pagination limit. Then we iterate through the results and display all the posts one by one as a list.

How to create the WordPress Template Page?

If this is the first time you are creating a WordPress template page, then it would be easy to use the existing template. Copy the page.php and paste it with a new filename.

Replace the content part with the above script to display all the posts and save it. Change the template name to all posts. Now you go to the editor and create a new post and use this new template. Now you have created a page which lists all the WordPress posts on a single page. Tada!

Vincy
Written by Vincy, a web developer with 15+ years of experience and a Masters degree in Computer Science. She specializes in building modern, lightweight websites using PHP, JavaScript, React, and related technologies. Phppot helps you in mastering web development through over a decade of publishing quality tutorials.

Comments to “How to Display All the WordPress Posts on One Page”

Leave a Reply

Your email address will not be published. Required fields are marked *

↑ Back to Top

Share this page