How to Create a Page for Blog Posts in WordPress

WordPress by default likes to show all your content in the format of a blog on the homepage. Some people like to create a custom home page in WordPress. If you want to use WordPress to run your entire site but also use it as a blog then this article has some tips for you on how to do that.

There are two different main methods where you can create a separate page just for blog posts. These methods depend on how you set up your home page. If you set up your home page by creating home.php then the method below is what you will need to follow.

Method One

  • Copy index.php and save it as blog.php
  • Make blog.php a custom page template.
  • Create a new page in your admin panel. Give the page a title, usually blog and select its custom page template like in the second step.
  • Publish your page.

You will then need to edit the blog.php file by finding the loop. It should look similar to this.

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Go ahead and replace this code with the following:

<?php
$temp $wp_query;
$wp_query= null;
$wp_query new WP_Query();
$wp_query->query('posts_per_page=5'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>

The posts per page is going to tell WordPress how many posts it should display on each page. You can change this number to whatever you think will work best with your site.

Find the following line:

<?php else : ?>

Remove this as well as the 404 content. Your WordPress should already have a 404 php file for that.

Next you will need to find:

<?php endif; ?>

Replace this code with:

<?php $wp_query = null; $wp_query $temp;?>

Tada! You now have a page that will display just your blog posts.

Method Two

This method does not really use much code at all and is much simpler. However, it will not allow you as much customization as you may like.

You will want to create two pages, one should be your home page and the other should be your blog page.

Once you have your two pages set up, go to settings and then reading.

 

wordpress-reading-settings

You then need to choose the static page option and select the front page as your home page and the posts page as your blog page.

Leave a Reply

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