Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Making a single html file for my Nav (php?)

    This might be a php question, I'm not really sure because I am somewhat new to development.

    I am building a site that has a large and detailed navigation, with lots of subpages. I imagine that over time, I will be adding and deleting some pages, and will also need to make the corresponding change in my <ul> nav.

    As it is set up now, I'll need to open 20 different pages and edit each of their code. I can see this getting very tedious, confusing, and having a large likelihood that I'll mess something up accidentally.

    My question is: Is there a way of having my Header (and nav) as one single html or php file? So that I can only edit that one file, and it will change on all pages of my site (similar to editing a CSS style sheet). I am almost certain I have seen this done on Wordpress themes.

    Sorry if this is a stupid question! If someone could just point me in the direction of a tutorial or tell me what this is called, that would be great.

    Thank you!!

    Sophie

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Good morning sophshep,
    A server side include can do what you're wanting. You can edit the one file and any of your pages that have the include would reflect that edited file.
    Very handy.

    Have a look at a PHP Include Tutorial here.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • The Following 2 Users Say Thank You to Excavator For This Useful Post:

    marilynn.fowler (02-16-2011), sophshep (02-16-2011)

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    My question is: Is there a way of having my Header (and nav) as one single html or php file?
    Yes there is! Just make separate files to save the html markup (shouldn't be a complte document, just the only relevant <div>s or <ul>-<li>s ) of your header and nav. Then use include() statements to include them, wherever required.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    sophshep (02-16-2011)

  • #4
    New Coder
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Excavator saves the day! AGAIN!!!

  • #5
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It is sort of a PHP and XHTML question. So here is how you can go about it. Create your pages with the following format or comparable. The following would be index.php
    Code:
    <?php include("header.inc"); ?>
    <body>
    
    <div id="nav">
    <?php include("nav.inc"); ?>
    </div>
    
    </body>
    <?php include("footer.inc"); ?>
    Save your header file as .inc
    Code:
    <html>
    <head>
    <title></title>
    </head>
    Your footer file as .inc
    Code:
    </html>
    Then save your navigation XHTML in the following nav.inc. All should work out for you. If you need more help just ask. All of your pages must be renamed to end with .php or this will not work.


  •  

    Tags for this Thread

    Posting Permissions

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