SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Thread: Relative path

  1. #1
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Relative path

    I'm trying to create a relative link for an image, but I can get it to work for some reason. The page and the images folder are in the same folder.

    Why doesn't this path work?

    <img src="..IMAGES/sports-club.gif" width="613" height="357" alt="Gym bulding photo" id="Building" />



    This is the site

    http://devb.bambl.clients.blinkss.com/

  2. #2
    SitePoint Mentor bronze trophy
    ronpat's Avatar
    Join Date
    Jun 2012
    Location
    NJ, USA
    Posts
    2,507
    Mentioned
    61 Post(s)
    Tagged
    2 Thread(s)
    file addressing notation:
    Code:
    ../dirname/filename  (from the parent directory, go to path/filename )
    ./dirname/filename  (from the current directory, go to path/filename )
    /dirname/filename  (absolute addressing; relative to the root directory, go to /path/filename )
    dirname/filename  (same as ./)(from the current directory, go to path/filename )
    Delete the two dots before IMAGES.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx...I tried that before I believe and just now and it didn't work.....

  4. #4
    SitePoint Mentor bronze trophy
    ronpat's Avatar
    Join Date
    Jun 2012
    Location
    NJ, USA
    Posts
    2,507
    Mentioned
    61 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by BrianBam View Post
    Thx...I tried that before I believe and just now and it didn't work.....
    Try again. I made an error. The post has been edited. Sorry.

  5. #5
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still nothing...#Doh

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,176
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    This is the relative path to your images:

    src="wp-content/themes/Newport_Sports_Club/IMAGES/sports-club.gif"

    In a WP site, the "page" and the images folder are not usually (if ever) in the same folder.

  7. #7
    SitePoint Mentor bronze trophy
    ronpat's Avatar
    Join Date
    Jun 2012
    Location
    NJ, USA
    Posts
    2,507
    Mentioned
    61 Post(s)
    Tagged
    2 Thread(s)
    Thanks, Ralph.

    Ah, yes, WordPress uses URI paths for everything.

  8. #8
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, what folder is the page and style sheet supposed to be in then? I have 4 sites and they all have the pages in the theme's name folder (i.e.

    wp-content/themes/theme_name/index.php or header.php, etc.)

    And the images folder is in the same same folder as the index.php file.

    I feel like there is something missing here....

  9. #9
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,176
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Forget about page location in WP, as pages are dynamically created and have no actual "location". If you want buttetproof image links, always use this on this particular site:

    src="/wp-content/themes/Newport_Sports_Club/IMAGES/sports-club.gif"

    Note the / at the front. That way, the link will work from any part of the site, even in the stylesheet links.

  10. #10
    SitePoint Mentor bronze trophy
    ronpat's Avatar
    Join Date
    Jun 2012
    Location
    NJ, USA
    Posts
    2,507
    Mentioned
    61 Post(s)
    Tagged
    2 Thread(s)
    If the path that Ralph posted began with a slash, it would be an absolute path and should work from either the css or index page.
    Code:
    src="/wp-content/themes/Newport_Sports_Club/IMAGES/sports-club.gif"
    Off Topic:

    bested by Ralph

  11. #11
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wooohoooo! Thx.

    This worked,

    <img src="/wp-content/themes/Newport_Sports_Club/IMAGES/sports-club.gif" width="613" height="357" alt="Gym bulding photo" id="Building" />

  12. #12
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,176
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Glad we could help.

    Off Topic:

    Quote Originally Posted by ronpat View Post
    it would be an absolute path
    There's a lot of argument over whether that should be called "absolute" or not, and these days I side with those who call it a "root relative" path, reserving "absolute" for the full URL (such as http://mysite.com/wp-content/themes/Newport_Sports_Club/IMAGES/sports-club.gif). Only the full URL is truly absolute, as it works from anywhere, whereas the root relative link is only absolute within the content of the site itself (it's not even absolute in relation to the server the site sits on).

  13. #13
    SitePoint Mentor bronze trophy
    ronpat's Avatar
    Join Date
    Jun 2012
    Location
    NJ, USA
    Posts
    2,507
    Mentioned
    61 Post(s)
    Tagged
    2 Thread(s)
    BTW - the reason the following code does not work is because of the leading slash.
    Code:
    <img src="/IMAGES/sports-club.gif"
    dots, slashes and paths matter. See post # 2.

    Off Topic:


    Obviously, I lean toward the old fashioned, conventional definitions and usage.
    URL or URI means "universal resource locator or indicator", as in works from anywhere.
    absolute refers to a specific location (the top-most directory, on a computer).


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •