Image

How to create a custom page template in WordPress?

What is WordPress Template?

WordPress Page Template is a simple PHP script embedded in HTML page where we can design the layout and put the contents as per our requirement.

There are two parts of a page template

  1. Header
  2. Body

Header is the information part and for WordPress use. WordPress recognize these information in Header. And decide whether it is a page template or not.

<?php
/**
* Template Name: Interview Sortout Custom Page
* Template Post Type: post, page
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/

Template Name – A template is named as {my template name}. This option will be reflect in Layout option when we will create a Page or Post. Template name is not

Template Post Type – This is the scope of template , that where can we use this template. We have to specify that what post type can use this template.

Body is the main content representation. It organize the heading, Thumb images, content, breadcrumb, sidebar etc.


<?php get_header();?>
<div class="container">
	<h2 class="blog-title"><?php the_title(); ?></h2>
	<main><?php the_content();?></main>
	<aside><?php dynamic_sidebar('right-side-bar' ); ?></aside>
</div>
<?php get_footer();?>

 

A complete Page Template:

 


<?php
/**
* Template Name: Interview Sortout Custom Page
* Template Post Type: post, page
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
get_header();?>
<div class="container">
	<h2 class="blog-title"><?php the_title(); ?></h2>
	<main><?php the_content();?></main>
	<aside><?php dynamic_sidebar('right-side-bar' ); ?></aside>
</div>
<?php get_footer();?>
Yadav Dhananjay

Yadav Dhananjay

I’m Dhananjay — a free-spirit with a passion for technologies and blogging.

View all posts by Yadav Dhananjay →

4 thoughts on “How to create a custom page template in WordPress?

  1. Heya are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you need any coding expertise to make your own blog? Any help would be greatly appreciated!

  2. Normally I don’t read post on blogs, but I wish to say that this write-up very compelled me to check out and do so! Your writing style has been amazed me. Thanks, very nice article.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.