WordPress.org

Forums

Inserting WP Templates in External PHP Page (11 posts)

  1. ralph
    Member
    Posted 10 years ago #

    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.

  2. Avenir
    Member
    Posted 10 years ago #

    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.

  3. prissed
    Member
    Posted 10 years ago #

    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).

  4. ralph
    Member
    Posted 10 years ago #

    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_ ?>

    ?

  5. Joshua Sigar
    Member
    Posted 10 years ago #

    What's the error message exactly?

  6. idahocline
    Member
    Posted 10 years ago #

    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(); ?>´

  7. ralph
    Member
    Posted 10 years ago #

    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?

  8. kiss-my-kitty
    Member
    Posted 10 years ago #

    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. :)

  9. soldeace
    Member
    Posted 9 years ago #

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

  10. laxstar2
    Member
    Posted 9 years ago #

    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

  11. unquenched
    Member
    Posted 8 years ago #

    Wonderful! Much appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.