People always like to modify the homepage or show a static page as homepage but what if you also want to have blog along with the static or customized homepage then you will have to created a custom blog page template.
And as WordPress recently launched its new default theme Twenty Thirteen, a single column theme created specially to make people focus on the post content. I’m going to tell you how to create a blog page template in this theme.
There are several methods to create a separate blog page in any theme, but I’m going to do it through the easiest & the most straight forward method.
You will need:
- FTP Access or Cpanel Login
- A plain Text/Code editor (Notepad will do)
I am going to use Filezilla FTP software and notepad2 to do this complete job.
Okay, Let’s Start Now then.
Note: Although I am creating this template file directly in the twentythirteen folder, I suggest you to create a child theme instead, because all changes made in this folder can be lost while updating WordPress or the theme.
1. Login to your WordPress directory via FTP
4. Make a copy of index.php
5. Rename the copy as blog-page.php
6. Open the blog-page.php in text/code editor, to make the below changes.
At the top of page you will have to give a name to the new page template so the WordPress can recognize that a new page template has been added, for defining the custom page template
* The main template file.
* This is the most generic template file in a WordPress theme and one of the
* two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* For example, it puts together the home page when no home.php file exists.
* Learn more: http://codex.wordpress.org/Template_Hierarchy
* @package WordPress
* @subpackage Twenty_Thirteen
* @since Twenty Thirteen 1.0
Template Name: Blog Page
Now, Find The Loop which will look something like this:
<?php if ( have_posts() ) : ?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
And replace with:
$temp = $wp_query;
$wp_query = new WP_Query();
while ($wp_query->have_posts()) : $wp_query->the_post();
And as posts_per_page sounds like it tells WordPress how many post to output on the blog page, for example I have set it to 10 posts per page you can change it to whatever you like.
Next, Find the lines that looks like:
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
And remove them.
Last, Find the loop closer:
<?php endif; ?>
And replace with:
<?php $wp_query = null; $wp_query = $temp;?>
Okay you have now successfully created the page template, now you will have to upload it to the theme or child theme directory /wp-content/themes/twentythirteen the same place from where you downloaded the index.php file at beginning.
Now, go to WordPress admin panel and follow these steps:
1. Create New Page via Pages > Add New
2. Title Page as ‘Blog Page‘ or ‘Blog’ or anything else you want
3. Make sure the permalink is ‘blog‘, so the url will become site.com/blog
4. Under Page Attributes select ‘Blog Page‘ as Page Template
5. Publish the page
Okay Now You have the blog page working, you can view your page I’m sure it will have all the post as it was shown on the homepage. Please let me know if you have any question or anything goes bad while doing this, by leaving a comment below, I’ll surely try to help you out.