How to Create a Separate Page for Blog Posts in WordPress

Posted on June 21st, 2010 by in Tutorials | 49 Comments  
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:

<?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.

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.

Sources

Nathan Rice
Michael Fields

About

Editorial Staff at WPBeginner mainly Syed and David.

Post comment as twitter logo facebook logo
Sort: Newest | Oldest
nicole holler 5 pts

the article was very informative i am a student and i find this useful for my projects thanks again :)

I'm not a developer and so I had to use plugins to virtually create two separate blogs on one wordpress page. Here is my explanation (in non-developer terms), I hope it helps someone.

I was trying to make my main blog page look different then a category blog page and include different content. I would recommend three plugins that helped me to get the job done: Advanced Category Excluder, Widget Logic, and Redirection. It was a matter of being able to exclude certain posts from our main blog page (Advanced Category Excluder) then being able to exclude sidebar menu widgets from certain categories (Widget Logic). The Redirection plugin allowed me to direct the blogs category link that is part of our theme back to the main blog page. I hope these plugins will help someone else out. If you are curious about what it looks like then check out www.creeksidebiblechurch.org/sermons (this is a category page) and www.creeksidebiblechurch.org/blog (this is our main blog page).

ChelseyR 5 pts

Hi WPBeginner. This was and is exactly what I have been looking for. I think I have got it set up for the most part, but could you please tell me how I would go about only pulling certain posts to be put into my custom blog page and them also not showing up in my default blog?

I also am not sure how to style my custom blog posts in my custom page. If I style one with css it affects the other one. I hope that makes sense. I basically need two separate blog pages and them to be styled completely different and one only pulling from certain posts.

I read in the comments that I can accomplish this by pulling from a category, but I don't know exactly which function to use or where to place it. Any help would be so appreciate, AND THANKS AGAIN FOR A GREAT ARTICLE.

I found this article useful! Thanks for sharing!

Cindy L 5 pts

Thanks SO much! This solved my issue. I couldn't understand how simply creating a blank Page and then naming it Blog (and then referring to it in the Setting-Reading panel) could work. But it did! Thank you so very much.

jeckt84 5 pts

Can someone help me create a blog page for my site? I don't want to mess anything up. My site is http://www.ontimedeals.com/

wpbeginner 50 pts moderator

jeckt84 We can do it for you for a fee if you don't want to deal with codes.

marcywrite 5 pts

I've achieved my static home page and secondary blog page. However, my blog page is not allowing for comments? Using the Readings setting sets up comments for all pages except this one, the only one where I would like it. Any help here? Thanks?

arionarian 5 pts

many thanks to this tutorial, now i have solved my problems..

jgarnerprod 5 pts

Thanks much for the help! Like most stuff, I was "one click" away, but wasted 30 minutes trying to find it.

Thanks for showing the answer!

Jason

ChristianFlores 5 pts

Thanks for the great article but heres my question!

What if I not only want to have 1 blog space seperated from home page, but 2, or 3?

How do I go about seperating content so that when I click each seperate blog in the nav bar, different content comes up instead of having the same content plastered allover pages of the same layout.

Please let me know if you have any tips

-Chris

dorksgetlaid2 5 pts

Alright, here's what I'm running into:

I'm looking to add a static page to my homepage and a blog page as well.

So, to create my static template page I just copied the page.php code verbatim (and added the theme language at the top), and named the file home.php (mostly because I was lazy and I wanted everything to look identical, I think this is where I went wrong). Everything was recognized properly so I created the added the new page exactly the way I wanted to. But, then when I go to load my home page it just gives me code, nothing else. Something isn't loading properly. Is there somewhere I can go to get a generic wordpress page to use here? I think the page.php code is screwing me up.

The reason I made the home.php file for the static homepage was because it tells me to do so above. My main priority in all of this is getting the blog on my page to get new content. So do I even need to create the static home.php page to get a separate blog? Because technically my home page is the blog page with a few lines of code snipped out to make it look less like a blog post. And I'm ok with that.

http://www.stevengracelaw.com

Thanks!!! I'm almost there.

wpbeginner 50 pts moderator

dorksgetlaid2 You need to use Method 2 mentioned above in the tutorial for what you are trying to accomplish.

casey.friday 5 pts

You. ROCK.

I'm creating my own WordPress theme, and this was EXACTLY what I needed. Now, to find out how to display only the excerpt up until the "read more" bit for each post with that code...

giorgia1985 5 pts

Hi I follow all these points. However, I am not able to post any featured image or image gallery on my blog page . This is is my blog http://whatsonthecatwalk.wordpress.com/

Can you please help me with that?

Thanks

Giorgia

wpbeginner 50 pts moderator

giorgia1985 Our tutorials do not work with WordPress.com sites. These are only for self-hosted WordPress installs.

JP2003 5 pts

Hi. Everything seems to be working great.

However, I have been trying to use <?php next_posts_link(); ?> and the previous post links for pagination. However, the previous and next links are not showing/displaying.

I read on another blog that if this happens, put a parameter for the number of pages. However, when I do this the links do show and seem to work, but the pagination continues according to the paramenter even if there are no blog entries for those pages (just shows a blank page).

Any ideas how to get this to work?

Thanks.

martcol02 5 pts

That did it for me! Thanks. What does that last bit do?

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

Thanks

What I am looking to do is similar. I am looking to have a static page as well as the blog appear on the main page of my wordpress site. Right now going to the settings section will only allow me to do one or the other. any feedback would be appreciated.

This would be done through custom coding the home.php file. You can pull in custom content as well as pulling in the most recent posts via the loop.

Some themes support this out of the box (i.e. under Appearance/Theme Settings).

For example the Atahualpa theme from http://bytesforall.com

We have this exact setup (static home page plus blog) at http://thewebalyst.com which is implemented using Atahualpa without any custom coding.

Mark (in London)
theWebalyst.com

Yes you are correct. Many frameworks and good themes come with a blog template such as Genesis and others.

Hi good post but not quite what I am looking for. Can you have a blog nav button at the top that appears only on the blog pages but not on any other pages on your site?

You can use the conditional tags like is_page.

I'm assuming the original poster wanted a second blog page to add posts. I have a site where all my blog posts get displayed on the home page. I want to create 2 to 3 seperate pages where I can enter unique blog posts relavant to those pages. My site has the home page and bio page. I want visitors to click on 3 more headings to view my blog posts for each heading. Does the above methods help me or am I a different situation?

The fastest way is to select all those posts, and add a unique tag to them. Then you can utilize query_post variable on a specific page template and pull posts with that tag. For less code savvy users, manually creating a list is the only option. But hopefully the internal linking feature will make that job easy :)

Hi,

I use your trick and got solution, Thanks a lot :)

one thing that i would like to say is in my site i used page name "Repair blog" and i created "repair-blog.php" but it doesn't work. and finally i rename it with "page-repair-blog.php" and it's works.

Again thank you for sharing such a precious information.

Very useful stuff, Just what I was looking for.

Thanks for posting this up.

Missing endwhile; on code. This is what is causing the page to go white screen or throw the errror "unexpected $end"

You have to add the More Break in the loop if you want it to work.

Thank you so much for this tut! Just what I was looking for, but couldn't explain well enough to Google.

Thank you for this piece of code. You saved me so much time. I spent last 3 Days trying to figure out how to do that. I have one question, when i used your code it shows full post instead of like 5 lines and then link "more". How i can fix it? Thank you.

You have to change the_content(); to the_excerpt();

This is a great tutorial. This will work nicely with the framework i'm building. Thank you for posting this.

I tried replacing the but it doesn't exist in my file. I found this however: . And there are two these: . Regardless I made my best effort to change the page but got this error: Parse error: syntax error, unexpected $end in... which is the very last line of code (get_footer).

We cannot see your codes in the comments. Please email us the question if you can.

This white screens my page. I have no code on the template at all besides get_header() and get_footer()... when I add the code you've suggested, the page breaks. Any differences in this code with Wordpress 3? Do you have any ideas as to why this would break my page?

The code should work with WP 3.0.

Thanks a lot! I am new to WP and was having trouble displaying posts on a page.

Hi There, a great tip and very useful, could you tell me how you would add new posts to the new blog page rather than the first 5 of your main blog?

This trick is to be used for those who are using WordPress as a CMS and have a custom homepage. Don't understand your question clearly, so if you can explain a little bit more we would love to help.

I run a site called lovetextures.com where I add new posts every Monday, these are then placed on my homepage along with my other posts. What I am looking to do is add a blog to my site where I would like to keep my blog posts separate to my homepage posts.

Hope this clears it up a bit

From what it seems like that you do not want to display the monday posts in your blog. We assume that you are posting those in a specific category. You can use the query_posts function to exclude a specific category from a loop.

Nice post! I wasn't aware of the first method, only the second. So thanks for showing me a new way of doing it.

Me too. Your timing is amazing, thanks very much.

Can you explain a little more about the pro's and cons? I like the idea of using the built in mechanism but would like to know what the benefits of the first method are as I usually end up wanting to push things past the limit!

Mark

For developers, the first method is preferred because it gives you more control.

Mmm ok, you already said that in the article.

So my question remains unanswered.

Mark in th

@theWebalyst: for example, using the first method, you can edit the query to only pull blog posts from a specific category, or with a specific tag, etc.

I see, so somehow, following the built in feature removes the ability to customise some features? Or makes it more difficult?

Seems odd, but then I'm new to WordPress.

Thanks

Mark

Personally I use the second method. My portfolio site is built entirely on WordPress, custom page templates etc. I don't feel I've lost any control whatsoever by not using the first method.

Tweets about us: