By 

Make a Custom Page Template in a WordPress Theme

Make a Custom Page Template in a WordPress Theme

A custom WordPress page layout could be utilized for various purposes. A few thoughts include:

  • Show recent posts of each category
  • Embed Google Map or any script
  • List of all authors.
  • Recently uploaded images
  • Custom design page for the portfolio
  • Contact page

Basically all the pages and posts that are created on a WordPress website is handled by a template file named page.php. Making or editing a custom page layout in WordPress requires essential information on HTML, CSS, and PHP. 

Login to your hosting panel. In this example, I am using Cloudways – A CloudPoco. Navigate to /wp-content/themes folder. Open your current theme folder and Create a template and give the name whatever you want i.e about.php 

Copy the below code and paste in your template

<?php

/**

 * Template name: About Us

 * 

 *

 *

 *

 * @package Troma

 */

get_header();

$sidebar_pos = ”;

$show_sidebar_page = troma_get_page_opt( ‘show_sidebar_page’, false );

if ($show_sidebar_page){

    $sidebar_pos = troma_get_page_opt( ‘sidebar_page_pos’ );

}

?>

    <div class=”container content-container”>

        <div class=”row content-row”>

            <div id=”primary” <?php troma_primary_class( $sidebar_pos, ‘content-area’ ); ?>>

                <main id=”main” class=”site-main”>

                    <?php

                    while ( have_posts() )

                    {

                        the_post();

                        get_template_part( ‘template-parts/content’, ‘page’ );

                        if ( comments_open() || get_comments_number() )

                        {

                            comments_template();

                        }

                    }

                    ?>

                </main><!– #main –>

            </div><!– #primary –>

            <?php if ( ‘left’ == $sidebar_pos || ‘right’ == $sidebar_pos ) : ?>

                <aside id=”secondary” <?php troma_secondary_class( $sidebar_pos, ‘sidebar-fixed widget-area’ ); ?>>

                    <div class=”sidebar-fixed-inner”>

                        <?php dynamic_sidebar( ‘sidebar-page’ ); ?>

                    </div>

                </aside>

            <?php endif; ?>

        </div>

    </div>

<?php

get_footer();

Go to WordPress Admin Panel > Pages > Add New. You can see the new custom page template listed on the right side.

Create a new page and set its template to about us. Once done, Publish it.

4 Comments

  • 08/08/2021

    akash katkar

    Nice blog

  • 08/08/2021

    Ajay Pandey

    Good job nice blog..

  • 08/08/2021

    Samiksha belose

    Nice work
    Interesting!!!

  • 08/08/2021

    Sumit vane

    Excellent work

Comments are closed.

Similar Blog Posts

How to Create Multisite in WordPress

How you can create and set up a WordPress multisite to build a network of…

How to rank my WordPress website on Google?

Search engine optimization is an accumulation of techniques and strategies used to increase the range…

Best Way to style Contact Form 7

We should perceive how we can style individual fields in a contact structure. There are…