Creating custom page template from existing PHP site

It really is rather simple. Check out the Codex on Page Templates for more info.

  1. Make a copy the existing page.php file located inside your WordPress theme’s folder.
  2. Rename your page.php file to page-mypage.php
  3. 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 */

  1. 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;
    ?>
    
  2. Replace the entire loop with the relevant PHP code of your project

  3. 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”.
  4. Done!