It really is rather simple. Check out the Codex on Page Templates for more info.
- Make a copy the existing page.php file located inside your WordPress theme’s folder.
- Rename your page.php file to page-mypage.php
- At the very top of your new page-mypage.php file, right after the opening
<?php
tag add the following code to define your custom page template.
/* Template Name: My Page Template */
-
Now inside your page-mypage.php file locate the WordPress loop. It usually looks like this:
<?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; ?>
-
Replace the entire loop with the relevant PHP code of your project
- Now in WordPress you will have to add a new page named mypage and select your custom template (My Page Template) in the “Page Attributs” sidebar block. There will be a dropdown menu called “Template”.
- Done!