SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do you include an include within an include?

    I'm using this link...

    <?php include($periods."includes/navmenu.php"); ?>

    to include a SwapClass navigation menu on my pages.

    The include itself looks like this (though it's much bigger):

    <?php
    $todayDate = date("m-d-Y");
    echo '<div id="nav" class="menuDiv">';
    <div id="navsupport" class="menuDivHeader" onclick="P7_swapClass(1,\'mn3\',\'showIt\',\'hideIt\',\'div\');P7_swapClass(1,\'but3\',\'menuButMinus\',\'menuButPlus\',\'img\')"> <img id="navspacer3" src="' . $periods . 'images/spacer.gif" width="1" height="20" alt="Click here to learn how you can support this project." /></div>
    <div id="mn3" class="showIt">Please <a href="http://www.geobop.org/home/support/">support this
    project</a>.</div>
    </div>
    <!--END MAIN NAVMENU-->'
    ?>

    I want to customize the navigation menu so that it's a little different on each of my main pages - Home, Introduction, Facts, etc. Actually, the navmenu itself might be the same, but I want to add certain features. For example, on the Prehistory page, I want to add links to geological time charts.

    I was going to create separate navigation menus for each of my pages, when I realized I could simply add an include within the included navigation menu, triggered by a combination of class/id and echo functions to bring in another include.

    For example, I'm presently including the geological time charts with this link:

    <?php include($periods."includes/time.php"); ?>

    If I change it to this...

    <?php include($periods."includes/time/$mypage.php"); ?>

    then I'll get the "Home" version, where $mypage = 'Home';

    To cut to the chase, I want to stick change <?php include($periods."includes/time.php"); ?> to something like <?php include($periods."includes/special/$mypage.php"); ?> and insert it in my included navigation menu, but I apparently have to modify it somehow. Can someone tell me how to format it so I can insert it within an include?

    Thanks

  2. #2
    SitePoint Enthusiast ptolemy's Avatar
    Join Date
    Feb 2002
    Location
    Geneva, Switzerland
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IMHO you should limit your include file to generate only what is global among your pages. Once you start enabling unique attributes to the navigation based on th page you are viewing it seems that it would be easier to simply add the new features to the page where they belong. Consider that the include would have to perform something like a switch function for each page view. Furthermore, if you decide to add sub sections you may find that your include file will grow too large for easy maintenance. May seem insignificant but, and call me old-fashioned, but I think that weighing the gained performance versus the relatively 'convenience' of having your entire site's navigation tool coded in a single file shows that in the long run you'd be better off coding non global navigation items in the pages where they belong.


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
  •