如何将导航栏存储在一个文件中? [英] How to store nav bar in one file?

查看:118
本文介绍了如何将导航栏存储在一个文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站有一个导航栏:

 < 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文件中。

然后在你的其他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屋!

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