SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How do link inside other folders?

    hey all,
    i wanna know how to link a page if its another folder. i know it can be
    Code HTML4Strict:
    <a href="home.php">Home</a>
    which means its in root dir.
    1.what if there r folder namely about and in about folder i have a index page. how do i give its link to that?
    2. what if i have a incldues folder and i have giving links of other folder like i have menu in my includes folder and i have folders made out like about us and i wanna pull about us index page from about folder. how do i do that? i hope my question isn't confusing
    All those who wander aren't lost.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by emaarkhan View Post
    which means its in root dir.
    No, it means that it's in the same directory as the page that contains the link.

    Quote Originally Posted by emaarkhan View Post
    1.what if there r folder namely about and in about folder i have a index page. how do i give its link to that?
    That depends on where the 'about' folder is relative to the page that contains the link. If it's a subdirectory,
    Code HTML4Strict:
    <a href="about/index.php">About</a>

    If it's in a parallel directory.
    Code HTML4Strict:
    <a href="../about/index.php">About</a>

    In general,
    Code HTML4Strict:
    <a href="/about/index.php">About</a>

    Quote Originally Posted by emaarkhan View Post
    2. what if i have a incldues folder and i have giving links of other folder like i have menu in my includes folder and i have folders made out like about us and i wanna pull about us index page from about folder. how do i do that? i hope my question isn't confusing
    Use a root-relative link:
    Code HTML4Strict:
    <a href="/about/index.php">About</a>
    Birnam wood is come to Dunsinane

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,105
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by emaarkhan View Post
    i hope my question isn't confusing
    It is!

    If I am linking to the index.php file in the /about/ folder, I prefer to do this:

    Code:
    <a href="/about/">About</a>
    That way, you don't see "index.php" in the address bar.

    As for includes, if you have something like menu.php in your /includes/ folder, link to it like this from any page:

    PHP Code:
    <?php include $_SERVER["DOCUMENT_ROOT"] . "/includes/menu.php"?>
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  4. #4
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,881
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by emaarkhan View Post
    hey all,
    i wanna know how to link a page if its another folder. i know it can be
    Code HTML4Strict:
    <a href="home.php">Home</a>
    which means its in root dir.
    1.what if there r folder namely about and in about folder i have a index page. how do i give its link to that?
    2. what if i have a incldues folder and i have giving links of other folder like i have menu in my includes folder and i have folders made out like about us and i wanna pull about us index page from about folder. how do i do that? i hope my question isn't confusing
    If you start the href with a / then it always starts from the root directory,
    • <a href="/home.php">
    • <a href="/folder/help.php">
    • <a href="/folder/subfolder/page.php">
    • <a href="/otherfolder/file.php">

    This means that you can use the same link from anywhere on your site and it will always point to the same place.

    If you don't start the href with a / then it is relative to the file you are linking from. To go up a folder level, use ../
    So, if you are in /folder/index.php, to link to each of the files above using a relative format, you would use
    • <a href="../home.php"> (up one level)
    • <a href="help.php"> (already in the right folder)
    • <a href="subfolder/page.php"> (go into a subfolder)
    • <a href="../otherfolder/file.php"> (up one level and then into a different folder)


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
  •