WordPress

WordPress TutorialRemove Version from WordPress and StylesheetsRun WordPress local with XAMPPSecurity in WordPress - EscapingSecurity in WordPress - SanitizationThe Loop (main WordPress loop)Update WordPress ManuallyWordPress Actions and FiltersWordPress add action()WordPress add editor style()WordPress add menu page()WordPress Add ShortcodeWordPress add submenu page()WordPress add theme support()WordPress Add/remove contact info for users with user contactmethods filter hookWordPress Admin Dashboard WidgetsWordPress AJAXWordPress Alternating main loop (pre get posts filter)WordPress Child Theme BasicsWordPress Create a Post ProgrammaticallyWordPress Create Template for Custom Post TypeWordPress Creating a custom templateWordPress Custom exerpts with excerpt length and excerpt moreWordPress Custom Post TypesWordPress Customizer Basics (Add Panel, Section, Setting, Control)WordPress Customizer Hello WorldWordPress DebuggingWordPress Enqueuing scriptsWordPress Enqueuing StylesWordPress Function : wp trim words()WordPress Function: add action()WordPress get bloginfo()WordPress get home path()WordPress get option()WordPress get permalink()WordPress get template part()WordPress get the category()WordPress get the title()WordPress home url()WordPress How Can I integrate Markdown editor with Advance Custom Fields repeater Add-on.WordPress initWordPress Installation and ConfigurationWordPress Making network requests with HTTP APIWordPress Meta BoxWordPress Options APIWordPress Plugin creationWordPress Plugin developmentWordPress Post FormatsWordPress Querying postsWordPress Remove Auto Line Breaks from Content and ExcerptWordPress REST APIWordPress Secure your installationWordPress ShortcodeWordPress Shortcode with attributeWordPress ShortcodesWordPress SidebarsWordPress Site MigrationWordPress TaxonomiesWordPress Template hierarchyWordPress template includeWordPress the $wpdb ObjectWordPress the Admin Bar (aka The Toolbar)WordPress the title()WordPress theme and child-theme developmentWordPress ThemesWordPress wp get current user()WordPress WP Query() LoopWordPress WP-CLIWordPress WP-Cron



WordPress Creating a custom template

From WikiOD

Creating basic blank template[edit | edit source]

To create a custom template we first need to create php file in a theme directory. You can name it almost any way you want. For this example we will create example.php

One and only thing we need to define inside our example.php, to be recognized by WordPress as a template, is template name. We do that buy putting special comment at the top of a file, like this:

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

And now when we should see our template listed in Template dropdown in Page Attributes Box

WordPress Dashboard Add New Page section screenshot

Including header and footer in our template[edit | edit source]

Let's extend our template from above and include content from header.php and footer.php

Including header:

We will include header right after Template name comment

There are two common ways to do this. Both are right and work same, it's just about your style and how code looks

First way:

<?php
/*
Template Name: Example
*/
get_header();
?>

Second way:

<?php
/*
Template Name: Example
*/
?>
<?php get_header(); ?>

Including footer:

Including footer works the same way, there is only one thing we need to care about, and that is that we include footer after we included header. So the final template should look something like this.

<?php
/*
Template Name: Example
*/
get_header();
?>

<?php get_footer(); ?>

Custom template with content[edit | edit source]

We will further extend our template and include title of the page and a content

<?php
/*
Template Name: Example
*/
get_header();

the_title();
the_content();

get_footer();

And if you want you can wrap them with HTML elements like this

<?php
/*
Template Name: Example
*/
get_header();

echo '<h1>' . the_title() . '</h1>';
echo '<section> . 'the_content() . '</section>';

get_footer();

Or if you prefer working like normal HTML file, without using echo

<?php
/*
Template Name: Example
*/
get_header();
?>

<h1><?php the_title(); ?></h1>
<section><?php the_content(); ?></section>

<?php get_footer(); ?>

Credit:Stack_Overflow_Documentation