简体   繁体   English

每页都包含菜单

[英]Include menu on every page

Let's say I have a simple CSS layout and my menu is a column on the side. 假设我有一个简单的CSS布局,我的菜单就是一栏。 This menu is going to be on every web page (About 10 web pages). 此菜单将出现在每个网页上(大约10个网页)。 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)? 你会把它变成一个PHP页面吗?在那个<div>元素中包含一个名为menu或者其他东西的PHP文件,然后编辑那个PHP文件(所以我只需要编辑那个文件而不是每个网页)?

If this is raw PHP (no frameworks) then you simply include it. 如果这是原始的PHP(没有框架),那么你只需要包含它。

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'); 例如,如果您在名为foo的文件夹中有文件,并通过example.com/foo/somefile.php访问,则必须将include语句更改为include('../sidebar.php'); assuming sidebar.php is in the root. 假设sidebar.php在根目录中。

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. 只需将菜单代码保存为yourMenu.php并将其放在root中,就可以了。

i've used this trick before and it works well. 我之前使用过这个技巧,效果很好。 you can use this in conjunction with an include php 你可以将它与include php结合使用

Intelligent Navigation 智能导航

If you are using the Apache web server it's even more simple and faster to use server side include (ssi). 如果您使用的是Apache Web服务器,那么使用服务器端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 这是参考页面: http//httpd.apache.org/docs/2.2/howto/ssi.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM