Include menu on every page

寵の児 提交于 2019-12-23 22:51:16

问题


Let's say I have a simple CSS layout and my menu is a column on the side. This menu is going to be on every web page (About 10 web pages). If I have items on this menu in the form of links and such, how can I make it so that if I add a link on one page, it will add it to all pages? Would you just make it a PHP page and in that <div> element include a PHP file called menu or something, and just edit that PHP file (so I only have to edit that file and not every web page)?


回答1:


If this is raw PHP (no frameworks) then you simply include it.

include('sidebar.php');

Make sure that you can access the file from where you are including it though. If you have files in a folder called foo for example, and accessed via example.com/foo/somefile.php you will have to change the include statement to include('../sidebar.php'); assuming sidebar.php is in the root.




回答2:


As stated above, and include would do.

Drop this on every page you want your menu to appear:

<?php include("/yourMenu.php"); ?>

Just save the menu code as yourMenu.php and put it in the root and you are good to go.




回答3:


i've used this trick before and it works well. you can use this in conjunction with an include php

Intelligent Navigation




回答4:


If you are using the Apache web server it's even more simple and faster to use server side include (ssi). You can do the same for the footer and other common areas of your pages.

Here is the reference page: http://httpd.apache.org/docs/2.2/howto/ssi.html



来源:https://stackoverflow.com/questions/3428585/include-menu-on-every-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!