November 7, 2018
Create A New WordPress Page Template
Creating a New Page Template requires us to do 4 things in order to make things work, but first we’ll create a new .php file in the theme directory (/wp-content/YOUR-THEME/), such as page-homepage.php.
- Specify a page template name.
<?php /* Template Name: Homepage */ ?>
- Include the header
<?php get_header(); ?>
- Start the WordPress loop on the desired page & print the content
<?php // Start the loop. while ( have_posts() ) : the_post(); // Include the page content template. the_content(); // End the loop. endwhile; ?>
- Include the footer
<?php get_footer(); ?>
Full Code Example:
<?php /* Template Name: Homepage */ get_header(); while ( have_posts() ) : the_post(); // Include the page content template. the_content(); // End the loop. endwhile; get_footer(); ?>