| by Interview Sortout | No comments

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();?>