How to create & customize page template in WordPress

Do you want to create a custom page template? WordPress allows you to create custom layouts for all of your pages. page templates in WordPress are a great way to add structural variations. What is a Page Template? A page template gives you the ability to change your page structure on your site and also…

Do you want to create a custom page template? WordPress allows you to create custom layouts for all of your pages.

page templates in WordPress are a great way to add structural variations.

What is a Page Template?

A page template gives you the ability to change your page structure on your site and also an addition to adding new features.

In this time, you will learn how to create and customize a WordPress template as you want.

Creating a Page Template

For example, Install a twentytwentytwo WordPress theme.

Using an FTP client, locate your theme’s directory on the server.

In this screenshot, you can see those 3 files.

The appearance of your pages is controlled by your WordPress theme using the page.php template file.

page.html : default template

page-large-header.htmlpage-no-separators.html : custom template someone made.

To make a new template, I usually create a <code>templates</code> directory and upload them on the site.

Give the following template code:

<?php
/**
 * Template Name: My custom Page
 */
?>

If you are modifying a current theme you should be using a child theme after creating your child theme.

Apply your template to your pages after uploading the file by FTP.

Customizing a Page Template

You’ll notice that the page above will have no styling, and look very very little like the rest of your WordPress site (unless you have the simplest theme imaginable).

That’s because the file has one simple thing in it, and lacks functionality very common in all other theme pages.

It has no get_header(), get_footer(), or The Loop, calls that all your other theme files likely do.

In this case, you can create a basic page template with some functions in the file.

<?php
/**
 * Template Name: Custom Full Width
 * description: Page template without sidebar
 */

get_header(); ?>

<div id="primary" class="site-content">
  <div id="content" role="main">

    <?php while ( have_posts() ) : the_post(); ?>
      <?php get_template_part( 'content', 'page' ); ?>
      <?php comments_template( ’, true ); ?>
    <?php endwhile; // end of the loop. ?>

  </div><!-- #content -->
</div><!-- #primary -->

<?php get_sidebar(); ?>

<?php get_footer(); ?>

Please do not use the following file names to name your custom page templates:

style.css -The main stylesheet.

comments.php – The comments template.

single.php – The single post template.

page.php – The page template.

search.php – The search results template.

404.php – The 404 Not Found template.

Adding Options

 You can do this by registering meta boxes but this would add considerable unrelated code to the article.

There are several options to create a page template by using some plugins.

One of my favorite plugins, Advanced Custom Fields can do the heavy lifting for us.

Install Advanced Custom Fields. And then create a page template using the code in our previous example from above.

Once done, you can create a page and select the “Custom Post List” template.

You should see two options grouped in a meta box pop up under the editor.

Set these to whatever you would like and let’s get started on making our theme use these settings.

Once done, you can create a page and select the “Custom Post List” template. You should see two options grouped in a meta box pop up under the editor.

Set these to whatever you would like and let’s get started on making our theme use these settings.