How do I pass data from page content to the underlying PHP template

If you want to produce a page in WordPress whose structure and content are dynamically generated independent of the regular posts handling mechanism then:

  1. Create a new page with title “My Custom Page“. This generates the page slug ‘my-custom-page‘ by default.

  2. In the root of your active theme folder eg. \wp-content\themes\twentyeleven\ create a page template for this new page named page-my-custom-page.php.

  3. Put your custom php code inside the page template.

  4. Navigate to your-site.com/my-custom-page/ to see the results