• WPChina

    (@wordpresschina)


    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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.

    Thread Starter WPChina

    (@wordpresschina)

    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.

    Thread Starter WPChina

    (@wordpresschina)

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

    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.

    Thread Starter WPChina

    (@wordpresschina)

    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?

    Thread Starter WPChina

    (@wordpresschina)

    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” “https://www.w3.org/TR/xhtml1/DTD/xhtml1-

    transitional.dtd”>
    <html xmlns=”https://www.w3.org/1999/xhtml”&gt;
    <head profile=”https://gmpg.org/xfn/11″&gt;
    <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(); ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding header/footer to files outside WP?’ is closed to new replies.