WordPress.org

Ready to get started?Download WordPress

Forums

Adding header/footer to files outside WP? (7 posts)

  1. WPChina
    Member
    Posted 8 years ago #

    I have a php page residing in the root of my website, but outside of WP. I want it to have the same header and footer as the rest of my blog, but I am unsure how to do this. I tried a simple php include statement like this:

    <?php include("/home/website/www/wp-content/themes/classic/header.php"); ?>

    but nothing shows up when I try that. When I don't use the include, the file shows, but it lacks the header (and the footer when I add that as an include too). I am sure I am missing something very very simple, but what is it?

    Any ideas how to add the theme to these outside files? What should be the PHP code?

    tks!

  2. pcmt
    Member
    Posted 8 years ago #

    Copy the WP header and footer source using your browser's "view source" (from one of your WordPress pages) and put them each in files called header.htm and footer.htm, and then use php includes to add them to the non-WP pages. I don't think you can simply call up the WP header and footer file from outside WordPress.

  3. WPChina
    Member
    Posted 8 years ago #

    Yes that would work, but the header.php and footer.php have dynamic info that would not be captured. I am sure I saw a way to do this in this forum in the last month, but all my searches and googling has turned up nothing.

  4. WPChina
    Member
    Posted 8 years ago #

    Also... the reason why I need to keep the file outside WP is that it is a php script. For some reason I can't create a Page with the script, so I am trying to use it outside of WP instead... if somebody knows how to include a PHP script in a Page, this would solve my problem. ;)

  5. pcmt
    Member
    Posted 8 years ago #

    Why not make a WP template, write the script into it, and then make a WP page using that template? That should work, unless you're using something like echo $_SERVER['PHP_SELF']; in your script.

    Sorry... can't be more explicit as I don't know what your script is for.

  6. WPChina
    Member
    Posted 8 years ago #

    Hmm, I tried that and it can display, but the form code won't work. My page is a small PHP script with a form code that returns data to that page. Any other suggestions?

  7. WPChina
    Member
    Posted 8 years ago #

    FINALLY!!

    Well, 3 months after originally aslking this quesiton on this thread and many other thread. And 3 months after looking all over the Internet for how to do this, I finally figured it out, thanks to only myself. Some of you might think this is simple, but I had a very very very hard time trying to figure it out.

    And because I do not want anyone else to go through the headaches I had in figuring out how to do this, I am pasting the sample code for a sample page you can use to show the WP footer and header on pages outside your WP installation. Note: you should name the file *.php and the code for this is for you to place it within the root of the WP installation.

    If you see 'It Works" within the template of your blog, then you know it works... also, my template does not use a sidebar--only a header and footer.

    Here goes:

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

    <?php get_header(); ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-

    transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head profile="http://gmpg.org/xfn/11">
    <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo

    ('charset'); ?>" />
    <title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> » Blog Archive <?php } ?> <?php

    wp_title(); ?></title>

    <?php wp_head(); ?>
    </head>

    <body>
    It works!

    </body>
    </html>

    <?php get_footer(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.