WordPress create custom Page Templates

Custom page with minimum requirement

keep the template file inside your /wp-content/themes/{your theme folder}/

<?php /* Template Name: min Custom Page */ ?>

<?php 
get_header(); 
get_sidebar(); 
?>

<div id="container">
    <?php while ( have_posts() ) : the_post() ?>
        <h1 class="postitle"><?php the_title(); ?><hr /></h1>
        <div class="content"><?php  the_content();  ?></div>
    <?php endwhile ?>
</div>

<?php get_footer(); ?>

Here the commented part is very important “/* Template Name: min Custom Page */”

this Template name will be displayed in template selection dropdown

custom_page

 

Little bit advanced version. Here I have added Author details, date, edit link, Category, comments, next and previous post links

<?php 
/* 
* Template Name: Custom Page 
* Description: Page template description
*/ ?>
<?php 
    get_header(); 
    get_sidebar(); 
?>
<div id="container">

    <?php while ( have_posts() ) : the_post() ?>

        <h1 class="postitle"><?php the_title(); ?><hr /></h1>
		
        <div class="content"><?php  the_content();  ?></div>
		
        <div class="postinfo">
            Author: <span class="author"><?php  the_author(); ?></span> on <span class="date"><?php  the_date(); ?></span> 
            <span class="edit"><?php edit_post_link(__('edit?')); ?></span> <br>
            Category: <span class="cat"> <?php the_category(', ') ; ?></span><br>
            <span class="tags"><?php the_tags(); ?></span>
        </div>

        <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>

        <div class="navigation">
            <div class="alignleft"><?php next_post_link('Newer: %link') ?></div>
            <div class="alignright"><?php previous_post_link('Older: %link') ?></div>
        </div>

        <div class="comments">
            <?php if (comments_open()) comments_template(); ?>
        </div>

    <?php endwhile ?>

</div>

<?php get_footer(); ?>

 

Author: bm on May 12, 2016
Category: wordpress