how-to-create-wordpress-theme

How to Create WordPress Custom Theme – 6 – Setting up Blog page template & single post template & archive template

WordPress has options to choose blog page as Blog template in back-end. We are going to create Blog page in back-end and assign it to Blog template from settings. Now Blog template must list-out all posts with ‘read more’ links.

Let’s design it. Please note the front-page.php is responsible to set template for front page so we are using index.php file as generic blog template. So let’s copy-past content from index file to front-page.php and remove everything from index file to redesign as generic blog template.

Set up while loop with have_posts() and design the layout as per your need. There are some important functions here.

the_author_posts_link()Displays an HTML link to the author page of the current post’s author.
the_time()Displays the time at which the post was written.
get_the_category_list()Retrieves category list for a post in either HTML list or custom format.
the_excerpt()Displays the post excerpt.
paginate_links()Retrieves paginated links for archive post pages.

Setting up single post template which is single.php

We already have single.php file. setup the content by the_content() functions and you are good to go with this layout. Now please note there are link for Author, Category. When you click on it, it will start displaying template from index.php file because there is no specific template we set yet. To set specific template for Archive pages, we need to set archive.php file.

Here are some important functions we used on archive template.

is_category()Determines whether the query is for an existing category archive page.
single_cat_title()Displays or retrieves page title for category archive.
is_author()Determines whether the query is for an existing author archive page.
the_author()Displays the name of the author of the current post.
the_archive_title()Displays the archive title based on the queried object. Means we do not need to check whether it’s category archive or author archive or date archive. This latest function handle all archives.
the_archive_description()Displays category, tag, term, or author description.

So at this stage we have front page template (static yet), Single post template, Post archive template, Single page template. Front page having some custom post data so we will make front page dynamic at the end, section by section.