I am building a theme (parent theme) and I was advised to put custom page templates in theme root folder. I am copying theme twenty fourteen and found this theme using a separate directory called
page-templates for keeping custom page templates but it does not work with my theme?
Can i know why twenty fourteen doing this and how ? Do I need to do the same because this is WordPress theme and I think they do everything thing in a proper way.
Where to put custom page templates in theme?
Custom page templates in
page-templates folder are automatically recognized by WordPress.This folder is recommended for global or multi-purpose page-templates.
You can check more organizing theme files on theme development handbook.
but it does not work with my theme?
Are you sure you have template files with the correct header ?
You can put custom page template in theme: create “templates” folder in theme and put the page.
First you check the admin panel and create new page display template name in “Page Attributes”, like:
If is not, then open
archive.php in given this line:
<?php /** * The template for displaying Archive pages * * Used to display archive-type pages if nothing more specific matches a query. * For example, puts together date-based pages if no date.php file exists. * * If you'd like to further customize these archive views, you may create a * new template file for each specific one. For example, Twenty Thirteen * already has tag.php for Tag archives, category.php for Category archives, * and author.php for Author archives. * * @link http://codex.wordpress.org/Template_Hierarchy * * @package WordPress * @subpackage Twenty_Thirteen * @since Twenty Thirteen 1.0 */
Replace This Line
<?php /* Template Name: About Us */
and Refresh your admin panel, creating the new page.
Remember for all created custom page templates, make sure to write the code:
<?php /* Template Name: Contact Us */
Put Template name (should be separate name) on page template php file (on toop). like this:
<?php /* Template Name: Page Template Name */ ?>
your file name can be template-your_template_name.php in theme folder or in subfolder in your theme folder.