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:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Replace this top part with the code below:
<?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 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:
<?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:
<?php endif; ?>
Replace it with:
<?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.
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:
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.