在每个页面上包括菜单 [英] Include menu on every page

查看:114
本文介绍了在每个页面上包括菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个简单的CSS布局,我的菜单是一边的列。此菜单将在每个网页上(约10个网页)。如果我在这个菜单上以链接的形式存在这些项目,那么如何在一个页面上添加一个链接就可以将它添加到所有页面?你会做一个PHP页面,而< div> 元素包括一个名为菜单或某些东西的PHP文件,只需编辑该PHP文件(所以我只需要编辑该文件而不是每个网页)?

解决方案

如果这是原始的PHP(没有框架),那么你只需要包含它。

  include('sidebar.php'); 

确保您可以从包含它的地方访问该文件。如果您有一个文件夹名为 foo ,并通过 example.com/foo/somefile.php 您将不得不将include语句更改为 include('../ sidebar.php'); 假设 sidebar.php 在根中。


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)?

解决方案

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.

这篇关于在每个页面上包括菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆