Results 1 to 5 of 5

Thread: Include on Header plus link inside it

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Include on Header plus link inside it

    Hmm. Need help on designing a header (or even footer and navigator php files) that has a link that's not an absolute. A little explanation I guess should help.

    Here's my scenario. I got a header.php to be included at index.php (home page) and also included at index.php (at catalog directory under /). So something like this

    Code:
    /
      + index.php (Includes header.php)
      + header.php
      + catalog/ (Directory catalog)
        + index.php (Includes header.php)
    Header has a link for products that is <a href="catalog/">PRODUCTS</a>, so by the time the user clicks at PRODUCTS in index.php (home) it goes to catalog/index.php where includes a header with an <a href="catalog/">PRODUCTS</a>, so clicking the products there would give me a Not Found having a link like http://localhost/pcx/catalog/catalog/ where pcx is a project folder inside my localhost.

    Hope to have my questions clear. Thanks in advance.

  2. #2
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Include on Header plus link inside it

    <?php

    require ('header.php');

    ?>

  3. #3
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Include on Header plus link inside it

    i think tahts wat u want i dont really understand ur question could u explain better?

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Include on Header plus link inside it

    I can just <?php include "header.php"; ?> but then I'll explain a bit of a problem. Structure of my project is
    Code:
    /
      + index.php (includes header.php)
      + header.php
      + catalog/ (directory)
        + index.php (includes ../header.php)
    At header.php there's a link <a href="catalog/">PRODUCTS</a>, so at index.php (home, not the catalog directory) I can go to catalog/index.php buy just clicking it. Now at index.php (now in the catalog directory) the link <a href="catalog/">PRODUCTS</a> is still there because it is included from header.php. So clicking the link at index.php (now in the catalog directory) will give me a 404 because there is no catalog folder in the catalog folder.

    How do I design this thing? I mean I need help on placing things. Where should I place what and what should I place where?

  5. #5
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: Include on Header plus link inside it

    Its something thats bothered me for quite a while... but my dodgy solution is,

    For something in the root dir.
    Code:
    $currdir = ".";
    
    Header.php----
    print "<a href=\"" . $currdir . "/link\">";
    So if you were in the catalog directory, then you would make $currdir ".." I do believe. So just have the variable at the top of the page and it'll work. I think you could probably do it using some of the super global variables as well.. figure out the location of the current file and then if needed add a "../"
    Don't Rate my posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width