Wordpress

How to Create a Separate Page for Blog Posts in WordPress

By default WordPress display your content in a blog format on the homepage. Users often modify for their needs by creating a custom home page in WordPress. What if you want to use WordPress to run your entire static site, and also use it as a blog? Well in this article, we will show you how to create a separate page for blog posts in WordPress.

There are few different methods you can use to create a separate page for blog posts. It all depends on which method you used to create the custom home page. If you created the homepage by creating a file called home.php, then you want to follow the method below:

1. First copy your index.php file and save it as blog.php.
2. Make it a Custom WordPress Page Template.
3. Create a new WordPress page in your WP-Admin panel. Title the page Blog, and before you hit publish, make sure you select the custom page template as shown in Step 2.
4. Publish the Page.

Next you need to edit blog.php file. Find the Loop, which should look something like this:

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

Replace this top part with the code below:

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

The posts_per_page variable does exactly what it sounds like. It tells WordPress to display X amount of posts on each page. You may change the number from 5 to whatever you like.

Find a line that looks like this:

1 <?php else : ?>

Remove this code and any else code such as the 404 content etc. You should already have a 404.php file in place for that.

Next you need to find this code:

1 <?php endif; ?>

Replace it with:

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

Ladies and gentleman, you now have a separate page for blog posts. Depending on your permalink structure, you can link it in other sites such as twitter, facebook etc. You can also list it in your navigation bar with the WordPress 3.0 Custom Menus.

Method 2

If you want to use the built-in Static / Blog page method, then you can do so as well. This method is less code intensive, but it does not allow for customizations that some developers might want.

Create two new pages, one can be called “Welcome” or whatever you want to call your homepage. The next should be called “Blog” or whatever you want to call your blog page.

If you already have a file called home.php in your theme, then you will need to rename it to welcome.php and make it a Custom WordPress Page Template by adding the codes at the top. Then in your Welcome page, select the Welcome Template.

Go to Settings » Reading:

Settings / Reading in WordPress

Choose the Static options and select your two pages.

Once you do this, you are good to go. If you have any questions, feel free to ask in the comments.

Leave a comment