WordPress.org

Ready to get started?Download WordPress

Forums

alternative index file location (39 posts)

  1. Aaron_Law
    Member
    Posted 9 years ago #

    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?

  2. Kafkaesqui

    Posted 9 years ago #

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

  3. Aaron_Law
    Member
    Posted 9 years ago #

    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?

  4. Kafkaesqui

    Posted 9 years ago #

    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.

  5. Aaron_Law
    Member
    Posted 9 years ago #

    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

  6. Aaron_Law
    Member
    Posted 9 years ago #

    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?

  7. Kafkaesqui

    Posted 9 years ago #

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

  8. Aaron_Law
    Member
    Posted 9 years ago #

    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?

  9. Jonathan Landrum
    Member
    Posted 8 years ago #

    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

  10. vkaryl
    Member
    Posted 8 years ago #

    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.

  11. moshu
    Member
    Posted 8 years ago #

    Which index?

  12. Jonathan Landrum
    Member
    Posted 8 years ago #

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

  13. moshu
    Member
    Posted 8 years ago #

    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');
    ?>

  14. Jonathan Landrum
    Member
    Posted 8 years ago #

    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

  15. vkaryl
    Member
    Posted 8 years ago #

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

  16. Jonathan Landrum
    Member
    Posted 8 years ago #

    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.

  17. vkaryl
    Member
    Posted 8 years ago #

    That's the standard browser 404. I've never seen a "wp" 404.

  18. Jonathan Landrum
    Member
    Posted 8 years ago #

    Kubrick comes with a 404 that utilizes the site layout. For one thing, I think it looks better. For another, I'm getting two errors for every one encountered. It was working perfectly the last time I used WordPress as a CMS. I should have stuck with WP instead of going static, but I've said that at least thirteen times this week.

  19. vkaryl
    Member
    Posted 8 years ago #

    Yeah, I know you have, and I know you're really frustrated.... Stuff like this, especially when you look back and say to yourself "I REALLY screwed the pooch on this" is an absolute PITA.

    I don't do kubrick so didn't realize it had a "special" 404. I've seen other themes that have them included, but I just don't care about stuff like that, browser 404's are fine.

    [When it's me getting the 404, the LAST thing I want is some site's fancy takes-3-hours-to-load-on-my-antique-dialup grinding away.... I want to know it's a 404 RIGHT NOW, so I can do something more useful....)

  20. Jonathan Landrum
    Member
    Posted 8 years ago #

    :o) Well, you certainly hit the nail squarely on the head! I've decided if I figure out how to fix it, great. Otherwise, it's not worth my time. Hey, at least it's not the index screwing up!

    Thanks for your time,
    Jonathan

  21. vkaryl
    Member
    Posted 8 years ago #

    Well, happy holidays to you Jon, I do hope you get it figured out eventually, or that someone brighter than I am can help you!

  22. Jonathan Landrum
    Member
    Posted 8 years ago #

    Thank you! Happy holidays to you, as well. Just getting back to WordPress is a Christmas gift I decided to give myself, even if it takes a few sleepless nights plugging away at it!

  23. vkaryl
    Member
    Posted 8 years ago #

    Hey, one last thought....

    Sometimes plugging away at something isn't the best way to do it. Take a break. Go out and play in the snow (assuming you have any - which I *sigh* don't!), take your kids to the ice-sculpture snow, meet your love at the carousel.... you get the idea.

    WP isn't going anywhere, and we aren't either. Look up at the stars and wish the world peace and happiness, and we'll see you in a couple days, okay?

  24. moshu
    Member
    Posted 8 years ago #

    Go out and play in the snow (assuming you have any - which I *sigh* don't!)

    Want to move to Winterpeg? This is my street...

  25. vkaryl
    Member
    Posted 8 years ago #

    Ooooohhhhh - I'll TRADE you! I'm retired, it can do that forever and I don't have to care....

    Here it was 60 degrees F and dry....

  26. Kafkaesqui

    Posted 8 years ago #

    Getting back on topic...

    If you use custom permalinks, you can (manually) add this ErrorDocument line to your .htaccess file to force the server to pass the error to WP and use the template which comes with your theme:

    ErrorDocument 404 /index.php?error=404

    You (of course) may need to modify the path to index.php, all depending on how things are set up on your site.

  27. vkaryl
    Member
    Posted 8 years ago #

    Where do you add that, then, Kafkaesquí?

  28. Kafkaesqui

    Posted 8 years ago #

    "to your .htaccess file"

  29. vkaryl
    Member
    Posted 8 years ago #

    Ah! Thanks.... heh, that's why I have host support - I don't DO that stuff....

  30. Kafkaesqui

    Posted 8 years ago #

    Hehe. Got it.

Topic Closed

This topic has been closed to new replies.

About this Topic