WordPress.org

Ready to get started?Download WordPress

Forums

Understanding 1.5 file hierarchy (8 posts)

  1. Lorelle
    Member
    Posted 9 years ago #

    I need a little clarification to understand the way the file hierarchy works in 1.5. I understand that much of it can be cleaned up by posting <base href="http://www.sitename.com/wordpress/" /> in the header, but I want to really understand the new hierarchy. I'll use images as an example.

    Since index.php in the root directory calls the index.php from the theme directory (and all the includes), links to images in a post using a theme are from the root directory or the theme directory?

    So a link to a graphic in sitename.com/images/cars/car1.jpg would be listed as images/cars/car1.jpg and work just fine or would it be relative from the theme directory as ../../../images/cars/car1.jpg.

    Can you see some of my confusion. The base reference would be easier, but I just want to understand the actual physical hierarchy.

    Thanks.

  2. chuyskywalker
    Member
    Posted 9 years ago #

    Because of the way it works, everything will be "relative" to the index.php file that is at the root of the install. This is because everything is included from there.

    This is applicable for any HTML element. Including files via PHP is a different beast, but for HTML things, you can assume that it's realtive to the teeny index.php file in the root.

    However, in the exames you gave, it's likey to work anyway.

    If you have installed at the root ( ie http://mysite.com/index.php ) then the path "../../../../../../../../../../images/hi.jpg" will work just as well as "images/hi.jpg".

    My preference is to just do "/images/hi.jpg" since I don't worry about it one way or the other then. :D

  3. Kafkaesqui

    Posted 9 years ago #

    This is a problem that crops up with custom permalink generation of virtual directories, and is more a web issue than a WP one, as all paths are relative to the location of a page as it appears within your url. If one were to actually point to

    sitename.com/wp-content/themes/theme-name/index.php

    your up-path notation would work. But with

    sitename.com/

    it tries to find 'images' in a directory three up from the root (which obviously fails). With this in mind, a link to

    sitename.com/images/cars/car1.jpg

    is best referenced as

    /images/cars/car1.jpg

    The initial slash specifies the path begins at the root of the site.

    Now, when it comes to requiring a path within theme templates specifically for things like an image directory for that theme, the tag bloginfo() provides new 1.5-specific parameter options for that:

    http://codex.wordpress.org/Template_Tags/bloginfo#Parameters

  4. Lorelle
    Member
    Posted 9 years ago #

    >>>"/images/hi.jpg"<<<

    Herein lies the problem that first started this for me. For me, without the base reference, "/images/" goes past "public-html" where all my public html (and php) files are listed (which technically makes it: "mysite.com/public-html/maindir/images") and it can't find the images directory because it isn't in the real "root" ("mystie.com/public_html/images") but in the "public-html/images/"...oh, I'm confusing myself.

    This was so much easier when my old server just had everything dumped in the root without having the public files in a public file directory. Ah, for the simplier life. ;-)

    .htaccess redirect helps a lot, but I want to keep it clean and not have a WHOLE bunch of redirects when I don't have to. The upkeep of all of these can be tiresome when things change.

    I think your explanations help me understand this a lot better. Thanks!

  5. Kafkaesqui

    Posted 9 years ago #

    "Herein lies the problem that first started this for me. "

    You just need to make everything difficult, don't you? ;)

  6. Lorelle
    Member
    Posted 9 years ago #

    My life story.

  7. DarkCryst
    Member
    Posted 9 years ago #

    I made a custom php function that pulled the info out from the http headers of the directory structure the page thought it was in - parsed that, and then used it to make sure I was working from the base directory.

    so in the php it just looked like:

    [code]
    href="<?php linkbase() ?>/myfolder/myfile.jpg"
    [/code]

  8. Lorelle
    Member
    Posted 9 years ago #

    ah, excellent. So this is a plugin or a custom function you edited into...the index.php page?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.