开发者

Have a single menu on multiple pages?

开发者 https://www.devze.com 2022-12-19 16:21 出处:网络
So I have a website and I\'m using a basic menu located at the top right corner of the screen. It\'s links are as follows:

So I have a website and I'm using a basic menu located at the top right corner of the screen. It's links are as follows:

| Home | Blog | Results | Pictures | Our Location |

Form time to time I need to add a new link to the menu or change where one of the links points to. This means that on every page that the menu exist I must manually change the link. Surely there is some way to have 开发者_如何学Goa master menu that is just put on every page.

Or am I dreaming?


Put the menu in a separate file and include it on the server side, either using a full-blown scripting language like PHP (one line) or using SSI.


There are various ways to do this. It depends what you have access to on the server. Possibly the simplest mechanism is server-side includes. You would just have a file that contains the menu and include it on every page.

You can also do this with every programming language in more or less elegant ways.

EDIT: The SSI is quite simple. You can just make a /header.html file, then do:

 <!--#include virtual="/header.html" --> 

in the appropriate place.


use the PHP include on all your pages

<?php include 'includes/menu.php'; ?>

and have a separate menu.php within a folder named 'includes'. you'll need to save all oyur pages as .php

you can make your footer as an include too


I think this is the easiest way of doing it without a server side language. Use a javascript library like W3Data. All you need to do is add the w3-include-html attribute to your div. Done!

If your menu is in a file called menu.html you'd do something like this.

<div w3-include-html="menu.html"></div> 


Have a server side program determine what menus and locations of the links need to be there. Then use ajax to periodically poll the server side script to get the contents of the menu at the current time.

It'd be easy to have it send an xml data back like:

<menu>
    <link name="Home" href="destinationhome.html"/>
...
    <link name="Pictures" href="....html"/>
 </menu>

Then build your links from that data.


You can generate pages from templates before uploading them: See Template Toolkit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号