How to create custom php script page

Question

If you want to add custom page in WordPress, you need to add your custom PHP file into currently activated theme ( /wp-content/themes/ ) folder.

Suppose you have child-theme. Put the file to child-theme folder. Then goto page section, Click Add New.

In Page Attributes, Choose Template as your PHP File.

Open the Page.php file, It’s available from the theme folder. Copy the all thing except header and paste it into your PHP file. Your PHP file must need following codes.

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

<?php get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php
        // Start the loop.
        while ( have_posts() ) : the_post();

            // Include the page content template.
            get_template_part( 'template-parts/content', 'page' );

            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) {
                comments_template();
            }

            // End of the loop.
        endwhile;
        ?>

    </main><!-- .site-main -->

    <?php get_sidebar( 'content-bottom' ); ?>

</div><!-- .content-area -->

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

0
nyedidikeke 7 years 2014-05-03T17:46:56-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse