Reputation: 109
I want to make php file "demo.php" in geany editor and then I want to add that page in my website.To do this task I have add "demo.php" in folder "wordpress/wp-content/themes/my_wesite_theme" ,after that my wordpress show that file as template "demo" , up to this its ok.
After that i want to add new page "new-page-of-site" in wordpress which take template of "demo" which is my php file template ,after selection of that template when i view "new-page-of-site" in browser it show only output of that page without wordpress theme ,so how can I include wordpress theme in that page.
Upvotes: 0
Views: 281
Reputation: 20925
This is a simple process and is very easy to do.
First of all, you need to name the template correctly. This just means adding the prefix page-
before the name of the template. Like so:
page-demo.php
Next, you have to add a tiny bit of code to the top of the template page just so that WordPress will know what the template is called.
Open up the new page-demo.php
that you have created, and add this code to the top:
<?php
/*
Template Name: Demo
*/
// names the template
get_header(); // gets the header detail
?>
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
//
} // end while
} // end if
?>
<?php
get_footer(); // gets the footer detail
?>
I've added some code for the actual page but you'll want to change it up to fit your actual page layout.
When you get into the WordPress admin area for adding new pages, on the right hand side below the save button, you should have an area for changing the template, just choose the new option, save and then you should be able to view the page with the new template.
Upvotes: 1