How to create and use wordpress page templates

Page templates allow you to creates custom pages, eg: creating a page to display infos about the author or any random php code that you wish or anything else.

A page template is defined by the following code, inserted on the firsts lines of the file:

<?php
/*
Template Name: template_name
*/
?>

(Insert it before the <?php get_header(); ?> tag.)

Basically you have to do this is a .php file that you will create in wp-content>themes>your-theme folder among other template files.

Lets say you want to show all posts, you will create a .php file show_posts.php

<?php
/*
Template Name: show_posts
*/
?>

To use it on your theme, write a page, and scroll down until you see a “Page Template” dropdown. In that dropdown select show_posts and save that page.

Tags: , ,

Leave a Reply

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

*
*