0
0
Wordpressframework~5 mins

Custom page templates in Wordpress

Choose your learning style9 modes available
Introduction

Custom page templates let you create special layouts for different pages on your WordPress site. This helps make pages look unique and fit their purpose better.

You want a landing page with a different design than the rest of your site.
You need a full-width page without sidebars for a portfolio.
You want a contact page with a custom form layout.
You want to show a special header or footer on certain pages.
You want to create a blog page with a unique style.
Syntax
Wordpress
<?php
/*
Template Name: Your Template Name
*/

get_header();
?>

<!-- Your custom HTML and PHP here -->

<?php get_footer(); ?>
Place this code at the top of a PHP file inside your theme folder.
The 'Template Name' comment tells WordPress this is a custom template.
Examples
This template creates a full-width page without sidebars.
Wordpress
<?php
/*
Template Name: Full Width
*/

get_header();
?>

<div class="full-width-content">
  <h1><?php the_title(); ?></h1>
  <?php while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>
  <?php endwhile; ?>
</div>

<?php get_footer(); ?>
This template is for a contact page with a special form section.
Wordpress
<?php
/*
Template Name: Contact Page
*/

get_header();
?>

<section class="contact-form">
  <h2>Contact Us</h2>
  <!-- Insert contact form shortcode or HTML here -->
</section>

<?php get_footer(); ?>
Sample Program

This is a complete custom page template. It shows the page title, a custom message, and the page content.

Wordpress
<?php
/*
Template Name: Simple Custom Template
*/

get_header();
?>

<main>
  <h1><?php the_title(); ?></h1>
  <p>This is a custom page template example.</p>
  <?php while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>
  <?php endwhile; ?>
</main>

<?php get_footer(); ?>
OutputSuccess
Important Notes

After creating a custom template file, assign it to a page in the WordPress editor under 'Page Attributes'.

Always include get_header() and get_footer() to keep site design consistent.

Use clear template names to easily find and select them later.

Summary

Custom page templates let you design unique layouts for specific pages.

Create a PHP file with a special comment to define a template.

Assign templates to pages in the WordPress editor to use them.