Hello WordPress Developer!
When I was new to wordpress blog devevelopment, I got few projects where the clients wanted a static homepage and a Blog link in the menu. In some other projects, the clients wanted to make the homepage to be semi dynamic; that means in the homepage we will show some wordpress data like three latest posts and other things will be static.
You know when we install WordPress the homepage is by default going to show the latest 10 blog entries. But now the homepage will be static, semi dynamic or anything. We will create a page and link it to default WordPress homepage.
OK. Take a look below of what I mean.
I tried it several ways. But I was not satisfied the available solutions. But luckily I figured out a stable solution. My solution does not need any plugin and it is simple too.
Step One: Create your custom homepage
First of all create your homepage as static, dynamic or whatever you want name it as home.php and remember that when visitors come to your site, they will see this file running as front page or website homepage. Upload it in the theme directory.
Step Two: Create your blog homepage templae
Create your blog homepage template and name it blog.php or anything. For clarity and relevance, let us name it blog.php and upload it in the theme directory.
Here is the code:
Template Name: Blog
// Which page of the blog are we on?
$paged = get_query_var('paged');
// make posts print only the first part with a link to rest of the post.
$more = 0;
//load index to show blog
load_template(TEMPLATEPATH . '/index.php');
Step Three: Create your blog homepage
Now create your blog homepage index and name it as index.php and then upload it in the theme folder.
Here is a sample of blog index.php file code:
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<?php the_content('Read the rest of this entry »'); ?>
<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
<?php endwhile; ?>
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Step Four: Create a page as Blog from admin panel
Now log in to the admin panel and create a page named as Blog. See the image below what I mean:
Do not save or publish this page right now. Follow the Step Five below before you save or publish this page.
Step Five: Set the blog page template
Now go to the Advanced Options section at the bottom. Under Page Template, select Blog template for this page.
Take a look of what I mean:
Now publish your page!
Now you may ask how this Blog template is coming? It is coming because of Step Two and of the first 5 (five) lines as below:
Template Name: Blog
Step Six: Check your site
Now go to your site and check everything! We are done!
I must say a big thanks to my American friend Joshua Knowles for his contribution to find out this smooth technique. Although Joshua is not a regular developer, he is a brilliant guy indeed!
Thank you for reading.