• I’m wondering how to place a new .php file in the webserver that is work for WP. By reading TheLoopInAction, I want to try it out: The World’s Simplest Index Page. Therefore, I copy the code into a .php file, eg, called “thesimpleindex.php” and place it in the root directory of my WP blog, “/htdocs/blog/”.

    However, it doesn’t work: "Fatal error: Call to undefined function: get_header() in \htdocs\blog\test-thesimpleindex.php on line 2".

    I think it is due to the relative location between “header.php” and “thesimpleindex.php” and so I try to place the index into directory “/htdocs/blog/wp-content/themes/default/” but it couldn’t help.

    Do you know where should I place files, e.g. the index above and some archive script, that call to get header.php and footer.php?

Viewing 15 replies - 1 through 15 (of 38 total)
  • Doesn’t look like the php document is WordPress aware. For that, include wp-blog-header.php in the file before anything else, like so:

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

    Just make sure the path to wp-blog-header.php is correct (./ is the same directory as the file).

    Thread Starter aaron_law

    (@aaron_law)

    Do you mean that I should check the relative location of the header file from the script (thesimpleindex.php) that I install, whatever where the script it is?

    If I’ve gotten the idea, the following should be right (assume that the header.php locates is “/htdocs/blog/”):

    1. I install thesimpleindex.php in “/htdocs/blog/”, and so I should set it:
      <?php
      include('./wp-blog-header.php');
      ?>
    2. I install thesimpleindex.php in “/htdocs/blog/wp-content/themes/”, and so I should set it:
      <?php
      include('../../wp-blog-header.php');
      ?>
    3. Anyway, the rule is to set the relative location of the required file from the index file manually, right?

    Relative unless you can provide an absolute path, such as:

    <?php
    include('/home/username/htdocs/blog/wp-blog-header.php');
    ?>

    It’s dependent on your setup, of course.

    Thread Starter aaron_law

    (@aaron_law)

    I’ve got the point about relative location between files. That is, regardless the file type (none of .html nor .php is matter), I should set the correct path in the call script.

    However, which of the header.php is called (I see no header.php is placed in the root of WP’s directory, but in each of themes’ directory.)? And what is the relative location between the header.php and the thesampleindex.php (if I put thesampleindex.php in the root directory of WP “/htdocs/blog/”)? That is, should I specific a theme and type in the theme’s directory in the function include() in order to make thesimpleindex.php works?

    Thanks for your help. ;P

    Thread Starter aaron_law

    (@aaron_law)

    Sorry, I think I’ve got the file wrong.The file that shouble be included is “wp-blog-header.php” (which presents in the root of WP), instead of the “header.php” (which present in every theme directory) which I mentioned in the last post.

    By adding the code <?php include('./wp-blog-header.php'); ?>, The World’s Simplest Index Page works now.

    Now my question is: What is the wp-blog-header.php do? Does it hold the information of header.php and footer.php as a global setting and so the thesimpleindex.php knows where to find the header and footer in the current theme?

    wp-blog-header.php is the foundation for WordPress templating. Any php file which is going to incorporate WordPress template tags and functions requires it. Once it’s loaded, you can do anything WP-related, including using theme-related functions such as get_header() and get_footer().

    Thread Starter aaron_law

    (@aaron_law)

    kaf, you help me to get out of the cloud 🙂

    Now I know what does this sentence means in the WordPress Files.

    Decides what to display based on the parameters that are passed to the blog. Included from any page that wants to display WordPress content.

    It says “included from any page…”. However, I think it should be included once only for a script/theme. For example:

    1. Doesn’t matter is it “thesimpleindex.php” nor “narchives.php”, as they are individual files, the “wp-blog-header.php” must be included for each of them in order to make them function (they need the wp-blog-header.php as they display content from WordPress)
    2. When I develop a theme, I need to include “wp-blog-header.php” once only whatever how many files are written/created for the theme, as a theme can be seem as a big script.

    Am I got the right concepts?

    So, does this mean I put:
    <?php
    include('./wp-blog-header.php');
    ?>

    in index.php before what’s already there? Why doesn’t it just come that way? The problem I am having is that WP doesn’t recognize that I have a 404 file (using the default Kubrick theme.) Every other file that I’ve tried seems to work fine.

    ~Jonathan

    Only time this is useful is if it’s an index.php file on a NOT wp site.

    If this is a problem with your wp site, this sort of thing isn’t likely to help. Try using your control panel editor from your host account to edit your 404 file.

    Which index?

    @moshu: index.php in the root (I guess, but that only prohibited my site from displaying altogether.)
    @vkaryl: I opened it up and everything looks fine:
    <?php get_header(); ?>
    <div id="content" class="narrowcolumn">

    …(custom error message poem goes here)…
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    The only thing I modified was the actual message.

    In the WP root this is all you should have in the index.php:
    <?php
    /* Short and sweet */
    define('WP_USE_THEMES', true);
    require('./wp-blog-header.php');
    ?>

    Well, that’s what I’ve got, now. I quickly figured out that this particular index couldn’t be what they were talking about, so my post should probably be in a different thread. The problem I am having is localized to one file (as far as I can tell.) My 404 page is unrecognized.

    >>http://www.jonlandrum.com/foo

    I get a normal 404 not found page. What’s odd with that?

    You’re getting WP’s 404? I’m getting Flock’s 404 with an additional 404 error while processing the first one:

    Not Found
    The requested URL /foo was not found on this server.
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Viewing 15 replies - 1 through 15 (of 38 total)
  • The topic ‘alternative index file location’ is closed to new replies.