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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Menu on every page

    I have created a menu that I want to use one many pages. I have the style sheet linked. However, is there a way to like the actual content of the menu so that if i want to change a link I don't have to go to every page and edit it.

  • #2
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    Could you not just call the one menu page up from every page. My site has many pictures to view, each picture when clicked returns one to the index page. Something like this may help.

    www.exitfegs.co.uk

    Have a look at it. It won't take long.

    Frank
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • #3
    New Coder zfred09's Avatar
    Join Date
    Dec 2006
    Posts
    69
    Thanks
    0
    Thanked 5 Times in 5 Posts
    This can be done using a php function and an include. In another file use code like this to make the function.

    Code:
    <?php
    function menu(){
    echo 'put your menu html here';
    }
    ?>
    Then in any page you want to display the menu on simply use code like this.

    Code:
    <?php
    include "path to file where the above code is";
    ?>
    
    Then where you want to display it
    <?php
    menu();
    ?>
    And thats all.

  • #4
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,790
    Thanks
    8
    Thanked 131 Times in 129 Posts
    or a tad simplier:
    Code:
    <?php include("menu.php"); ?>
    and just in case heres an asp way:
    Code:
    <!--#include file ="menu.asp"-->
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • #5
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hey,
    Sorry for pulling back old posts, but I searched and found this post interesting. However, I'm new to PHP and was wondering if anyone could give help me out a couple of basic questions:

    - How should the html code look like inside the php-file? Can I include <html>, <head> and <body>-tags, or should I skip this?
    - Can I link to styling sheets inside the php-file?
    - How should the code be structured? Do I need to write all html-code on one single line, or can I use my "normal" (tree-)structuring of code?

  • #6
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ooops, wrong forum section. Sorry!

  • #7
    Regular Coder
    Join Date
    Feb 2007
    Location
    Canada
    Posts
    924
    Thanks
    10
    Thanked 56 Times in 55 Posts
    Quote Originally Posted by maim9 View Post
    Hey,
    Sorry for pulling back old posts, but I searched and found this post interesting. However, I'm new to PHP and was wondering if anyone could give help me out a couple of basic questions:

    - How should the html code look like inside the php-file? Can I include <html>, <head> and <body>-tags, or should I skip this?
    - Can I link to styling sheets inside the php-file?
    - How should the code be structured? Do I need to write all html-code on one single line, or can I use my "normal" (tree-)structuring of code?
    1. Skip the html, head and body tags if the 'calling' page already has them.
    2. Yes, you can add any html or php in the included file that would normally work in the 'calling' page. Includes are treated as html unless you set the php tags inside it to parse some php.
    3. as per above, the included file will be handled as an html snippet, so write the html exactly as you would on a regular page.

  • Users who have thanked jlhaslip for this post:

    maim9 (03-04-2008)

  • #8
    New Coder
    Join Date
    Mar 2008
    Location
    San Fernando Valley, CA
    Posts
    14
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by maim9 View Post
    - How should the html code look like inside the php-file? Can I include <html>, <head> and <body>-tags, or should I skip this?
    - Can I link to styling sheets inside the php-file?
    - How should the code be structured? Do I need to write all html-code on one single line, or can I use my "normal" (tree-)structuring of code?
    The answers are no, don't skip the tags, yes, you can link to a style sheet, yes you can use your "normal" code structure.

    Using an include for just the menu like Harbinger suggested (you just locate it in your page where you'd normally put all the menu code) is a great, simple solution. But what if you have more than just the menu that has to be consistent?

    Here's how I do it.

    First, create your page layout like you would a template - no content that will differ from page to page, just layout and structure; you know, the stuff that has to be the same on all the pages. Then, highlight the code from the very top down to where your main content goes and save it in a file called something like "header01.php" - even if it doesn't have any PHP code in it.

    header01.php:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>IPOonRamp Back Office Login</title>
    <link href="cms.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="wrapper">
    	<div id="header">
        	<h1 id="h1Main">Database &amp; Content Management</h1>
            <h2>IPOonRamp.com</h2>
            <h3>Back Office</h3>
        </div>
        <div id="mainContent">
    Then do the same from the bottom up to the main content.

    footer01.php:

    Code:
        </div>
        <div id="footer">
        	<p>All content &amp; images &copy;copyright 2008 The Amerigo Companies.<br />
    			All Rights Reserved.</p>
        </div>
        <div id="validation">
             <p>
        <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" /></a>
     <a href="http://jigsaw.w3.org/css-validator/"><img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" />
     </a>
    </p>
        </div>
    </div>
    
    </body>
    </html>
    Finally, surround what's left with PHP-includes.

    index.php:

    Code:
        <?php include("includes/header01.php"); ?>
        	<form style=";" method="post" action="index.php">
            	<p>Username:<br />
                <input name="username" type="text" /><br />
    <br />
    			Password:<br />
                <input name="password" type="password" /><br />
    <br />
                <input name="submit" type="submit" value="Log In" />
            	</p>
            </form>
        <?php include("includes/footer01.php"); ?>
    When it opens in a browser, the source code just looks like a plain old static HTML page.

    Code:
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>IPOonRamp Back Office Login</title>
    <link href="cms.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="wrapper">
    	<div id="header">
        	<h1 id="h1Main">Database &amp; Content Management</h1>
    
            <h2>IPOonRamp.com</h2>
            <h3>Back Office</h3>
        </div>
        <div id="mainContent">
        	<form style=";" method="post" action="index.php">
            	<p>Username:<br />
                <input name="username" type="text" /><br />
    
    <br />
    			Password:<br />
                <input name="password" type="password" /><br />
    <br />
                <input name="submit" type="submit" value="Log In" />
            	</p>
            </form>
            </div>
        <div id="footer">
    
        	<p>All content &amp; images &copy;copyright 2008 The Amerigo Companies.<br />
    			All Rights Reserved.</p>
        </div>
        <div id="validation">
             <p>
        <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" /></a>
    
     <a href="http://jigsaw.w3.org/css-validator/"><img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" />
     </a>
    </p>
        </div>
    </div>
    
    </body>
    </html>
    The advantage to something this basic is that you could have 63 pages on your web site that have to all look the same except for the main content - header, menu, footer. If you want to change the menu, or something in the header or footer, you only have one place where you need to edit that info and all 63 pages will change. And you don't even need to know PHP except for the syntax for an include. This simple trick is easier and works better than a Dreamweaver template!

    By the way, I can't take credit for this trick - I learned it from Kevin Skoglund's PHP tutorial at Lynda.com (no, I'm not THAT Lynda).
    Lynda the Collaborator
    L.J. Williams Design
    Any sufficiently advanced technology is indistinguishable from magic. - Clark's Third Law


  •  

    Posting Permissions

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