Home arrow Web Authoring arrow Create PHP Pages that Use WordPress Templates

Create PHP Pages that Use WordPress Templates

In this programming tutorial, you will learn how to create standalone PHP pages that use (or inherit) WordPress template files.

Author Info:
By: Codex-M
Rating: 5 stars5 stars5 stars5 stars5 stars / 7
June 10, 2011
  1. · Create PHP Pages that Use WordPress Templates
  2. · Using wp-load.php WordPress Theme Loader

print this article

Create PHP Pages that Use WordPress Templates
(Page 1 of 2 )

If you are a regular user of WordPress, you might find yourself wondering if it is possible to create a PHP template file (with a .php extension) that uses or inherits WordPress template files. Before we answer that question let's look at what the word “inherits” means:

1.) The created standalone PHP template will use the theme used by your main Wordpress website.
2.) Every elements is dynamic. This means if you update your main Wordpress website by adding new posts, it will also be reflected - automatically - on your created template files.
3.) The header, sidebar, and footer element will be using your main Wordpress website theme files.

The only thing that is “unique” is, of course, the content. This type of page has a lot of applications. You know already that the default WordPress installation will not allow you to execute your own customized written PHP scripts directly inside the WordPress post. Although there are plug-ins that support this, they can be prone to incompatibility issues and also a security risk.

By utilizing standalone pages to use your own Wordpress themes, you can basically run PHP scripts in the content section of your pages, independent of the WordPress database.  To have all your created PHP template files have the same look and feel as your main Wordpress website, you should follow this structure:

Your standalone PHP page contains hard-coded content (the PHP script or HTML code). This means that the content is not stored in the Wordpress database. The rest of the page elements (header, sidebar, and footer) all inherit from your Wordpress theme files and are pulled from the Wordpress database.

Getting Started: Create a Blank PHP template that depends on Wordpress page template

All newly created dynamic and standalone pages (such as those shown in the screenshot above) will be created based on your existing Wordpress page template (this is known as “page.php” and it is found in your Wordpress theme files). The following are the steps you need to take:

1.) Login to your WordPress admin panel.
2.) Go to Appearance, click Editor.
3.) Under “Templates”, you will see a lot of WordPress theme files.
4.) Click “Page Template” to view the source code of the page.php.
5.) Control + A to select all source code and then copy it to your favorite PHP editor (gPHPedit, for example in Ubuntu). Save it as “standalonetemplate.php” on your desktop computer.

6.) Depending on your WordPress theme, below is the standard page.php code (it might look slightly different with other WordPress themes):

<?php get_header(); ?>
<div id="content" class="section">
<?php arras_above_content() ?>
if ( arras_get_option('single_meta_pos') == 'bottom' ) add_filter('arras_postfooter', 'arras_postmeta');
else add_filter('arras_postheader', 'arras_postmeta');
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
 <?php arras_above_post() ?>
 <div id="post-<?php the_ID() ?>" <?php arras_single_post_class() ?>>
        <?php arras_postheader() ?>
        <div class="entry-content">
    <?php the_content( __('<p>Read the rest of this entry &raquo;</p>', 'arras') ); ?> 
        <?php wp_link_pages(array('before' => __('<p><strong>Pages:</strong> ', 'arras'),
   'after' => '</p>', 'next_or_number' => 'number')); ?>
        <!-- <?php trackback_rdf() ?> -->
  <?php arras_postfooter() ?>
      <?php if ( arras_get_option('display_author') ) : ?>
        <div class="about-author clearfix">
        <?php endif; ?>
 <?php arras_below_post() ?>
<?php endwhile; else: ?>
<?php arras_post_notfound() ?>
<?php endif; ?>
</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Examining the source code above, it will start loading your WordPress headers, then your WordPress content. After loading the content, it will load the sidebar and footer at the end. So the question is: “How will you able to modify this template to work with standalone PHP pages outside your normal  WordPress installation?”

This is where you will use “wp-load.php”.

blog comments powered by Disqus

- Top WordPress Plugins for Social Media
- How to Install WordPress on WAMPP
- More of the Best Wordpress Plugins for Comme...
- Top Wordpress Plugins to Fight Spam
- More of the top Drupal modules for SEO
- Top Drupal Modules for SEO
- More Top Wordpress Plugins for SEO
- Website Optimization Tips
- Backup and Restore a Drupal Website and Data...
- 5 Best Web Font Services
- Web Font Embedding Services
- Joomla Site Administration
- Create PHP Pages that Use WordPress Templates
- Top Joomla Extensions for Social Networking
- Drupal Modules for Site Navigation

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials