Posts Tagged ‘wordpress template’

Adding template page from plugin

April 18, 2011 Leave a comment

Hello readers,

I have found a very simple solutions to assign a template page to specific or all pages . According to my previous tutorial for creating the template page and placing into the wordpress current template.

For creating the template you need to add comment on the top of the page as known from my blog

Template Name: new template

Now what ever you want add the functionality to the page and then add header/footer as on your preference.
Now your template file is ready to run or attach to page. But now no need to copy that php file to the template folder of wordpress.
all you need to do is call the following hook

add_filter( 'page_template', 'catch_plugin_template' );

Now this will be called on every page/post load.

add_filter( 'page_template', 'catch_plugin_template' );
function catch_plugin_template($template)
$template = WP_PLUGIN_DIR . '/yourpluginname/template-file.php';
return $template;

Now the above could will execute on every page and the template would be assigned to all the pages you have created.

Thank You for reading.

Creating Template page

March 2, 2011 3 comments

Hello Readers, I am back after a long time today will give you a short tutorial for the wordpress custom template page.
Firstly remember the changes which would be done are template specific. So if the template changed ,changes are gone.
firstly go into the template folder ie


So for now i m considering the default template for wordpress 3.0 is twentyten. Now create a empty file inside the the twenty ten folder .


Now we have the custom template which do not contain any code. but now you might be thinking where to access this template file . But wait this file wont show up into the wordpress admin area unless u write the following code.

Template Name: new template

now we could say we have a template page installed on to the wordpress current theme . You could write any html code or could copy the content from the page.php and delete the content which you don want to display . So now will add the following code.

Template Name: new_template
 <div id="container">
 <div id="content" role="main">

      This is a  custom Template Page
      <!-- Any HTML Content Here -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

As you can see above will give the same look as the other but here you have freedom to write any static or call any php function or any functionality you want to extend to this template or wordpress. So now we have a complete page where we could have our custom page.So now its time to access this new template page. Step1: Got the Pages->Add New Step 2: Select the new template created . Template page As you can see you will get the template page that we created into the combobox. So now do not enter any content into the page just leave blank and select the template page and publish the page. Then from the main menu you could see the menu is created and also the content you have added . Thank you all for reading hope you it could have been a useful article.

%d bloggers like this: