Support » Themes and Templates » Inserting WP Templates in External PHP Page

  • You have a theme. In your theme you have templates, like header and footer.

    Now, you wish to implement these headers and footers into a external PHP page, say a photo gallery.

    In other words, is there a way to insert WP templates (which have been already parsed by WP) into a PHP document?

    Remeber, the templates contain WP-specific tags. These need to be parsed first.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Simply add:

    <?php
    require_once('./wp-blog-header.php');
    ?>

    to the beginning of the file you want to include the templates in. Of course, change the path so that it goes to your actual WordPress installation path.

    Then you can include the templates at your will. You could also use the get_header, get_footer and get_sidebar functions to include the respective templates.

    I couldn’t get the relative path to work, but it did work with the absolute server path (i.e. /home/me/www/wp-blog-header.php).

    PROBLEM

    I’m using a photo gallery.

    The template for the photo gallery is a php file.

    The problem is that the photo gallery uses echo tags, like WP. Eg, <?php echo $album['link']; ?>

    And the photo gallery then parses those calls.

    WP thinks that the <?php echos for the gallery are for WP, thus produces errors.

    By inserting <?php require_once('./wp-blog-header.php'); ?>, WP is applied to the whole document. Is there a way to call WP to parse only a single tag when necessary?

    Example (and this is just an example)
    <?php _start wp parsing_ ?>
    <?php get_header ?>
    <?php _end wp parsing_ ?>

    ?

    What’s the error message exactly?

    The header :
    ´<?php $posts_per_page = ‘-1’; require_once(‘wp-blog-header.php’); ?> ´
    ´<?php get_header(); ?>´

    the code of the “body”

    if you use a sidebar : ´<?php get_sidebar(); ?>´
    the footer call : ´<?php get_footer(); ?>´

    What’s the error message exactly?

    Fatal error: Call to a member function on a non-object in /home/**/public_html/wp-includes/functions.php on line 1068

    Couldn’t this be caused by the similar-to-WP photo gallery tags?

    Avenir, thank you so much! Your “require_once” code (I’m a PHP newbie *blush*) solved my problem! I’ve spent the last two or so hours searching here and google for a way to use the WP themes on external php pages.
    You rock. 🙂

    I’m getting exactly the same problem. If anyone already found a solution, please let me know.

    i get this error:

    Warning: Invalid argument supplied for foreach() in /home/northwe5/public_html/wp-includes/template-functions-category.php on line 393

    i have code included to only show the archive when in category 2, i think this is the cause of the problem, but i dont know how to fix it

    Wonderful! Much appreciated.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Inserting WP Templates in External PHP Page’ is closed to new replies.