如何将导航栏存储在一个文件中? [英] How to store nav bar in one file?
问题描述
我的网站有一个导航栏:
< div id ='menu'>< ul>
< li>< a href ='index.html'>主页< / a>< / li>
< li>< a href ='about.html'>关于我们< / a>< / li>
< li>< a href ='http://www.brownpapertickets.com'target = _blank> Ticket Sales< / a>< / li>
< li>< a href ='merch.html'>商品< / a>
< ul>
< li>< a href ='merch.html'>产品< / a>< / li>
< li>< a href ='cart.html'>购物车< / a>< / li>
< / ul>
< / li>
< li>< a href ='past.html'>过去显示< / a>
< ul>
< li>< a href ='photos.html'>图片库< / a>< / li>
< li>< a href ='vids.html'>视频剪辑< / a>< / li>
< / ul>
< / li>
< / ul>< / div>
我想将它存储在一个中心位置,以便每次添加超链接或其他我不必编辑每一个文件。什么是最好的方式来做到这一点?
假设您使用PHP等脚本语言,只需保存上述HTML在一个名为 header.php
(或者你喜欢的东西)的php文件中。
include_once('header.php');
并且它会将HTML放在那里。
一些资源适合您:
http://php.net/manual/en/function.include.php
http://www.php.net/manual/en/function.include-once.php
http://php.about.com/od /tutorials/ht/template_site.htm
享受!
I have a navigation bar for my website:
<div id='menu'><ul>
<li><a href='index.html'>Home</a></li>
<li><a href='about.html'>About Us</a></li>
<li><a href='http://www.brownpapertickets.com' target=_blank>Ticket Sales</a></li>
<li><a href='merch.html'>Merchandise</a>
<ul>
<li><a href='merch.html'>Products</a></li>
<li><a href='cart.html'>Shopping Cart</a></li>
</ul>
</li>
<li><a href='past.html'>Past Shows</a>
<ul>
<li><a href='photos.html'>Photo Gallery</a></li>
<li><a href='vids.html'>Video Clips</a></li>
</ul>
</li>
</ul></div>
I want to store this in one central place so that every time I have to add a hyperlink or something I don't have to edit every single file. What's the best way to do this?
Assuming you are using a scripting language such as PHP, you simply save that HTML above in a php file called header.php
(or something to your liking)
Then in your other php files you write:
include_once('header.php');
and it will plop that HTML right in there.
Some resources for you:
http://php.net/manual/en/function.include.php
http://www.php.net/manual/en/function.include-once.php
http://php.about.com/od/tutorials/ht/template_site.htm
Enjoy!
这篇关于如何将导航栏存储在一个文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!