帮助编码导航栏 [英] Help coding a navigation bar
问题描述
我厌倦了不断更改我们众多
顶级页面上的导航栏,所以我最终使用了一个仅包含html的文件。这里是
a片段:
< div class =" navleft">
< a href = " home.php">主页< / a>
< div class =" navspacer">< / div>
< a href = " newitems.php">< b>新商品了!< / b>< / a>
< div class =" navspacer">< / div>
< a href =" items1.php"> items 1< / a>
< a href =" items2.php"> items 2< / a>
< a href =" items3.php"> item 3< / a>
< div class =" navspacer">< ; / div>
< a href =" blah blah"> blah blah< / a>
< a href =" contact.php"> ;< b>联系我们!< / b>< / a>
< / div>
现在我要修改导航栏,以便活动页面不是可点击的
链接,并以不同的方式显示。例如,当项目1页面处于活动状态时,
导航栏应该具有
< div id =" activeselection"> items 1< / div>
而不是href行。
我可以将包含文件转换为php代码并且有一大堆
if-then - 每个导航栏条目的组合,但这非常混乱。所以php
gurus,我怎样才能最好地编写单个包含文件?
谢谢。
jay dub
I got tired of constantly changing the navigation bar on our numerous
top-level pages, so I finally used an include of an html-only file. Here''s
a snippet:
<div class="navleft">
<a href="home.php">Home</a>
<div class="navspacer"></div>
<a href="newitems.php"><b>New Items!</b></a>
<div class="navspacer"></div>
<a href="items1.php">items 1</a>
<a href="items2.php">items 2</a>
<a href="items3.php">items 3</a>
<div class="navspacer"></div>
<a href="blah blah">blah blah</a>
<a href="contact.php"><b>Contact Us!</b></a>
</div>
Now I want to modify the nav bar so that the active page is not a clickable
link and appears differently. E.g., when the items 1 page is active, the
nav bar should have
<div id="activeselection">items 1</div>
instead of the href line.
I can turn the include file into php code and have a whole mess of
if-then-else combos for each nav bar entry, but that''s pretty messy. So php
gurus, how can I best code a single include file?
Thanks.
jay dub
推荐答案
我可以将包含文件转换为php代码,并且整个过程都很乱每个导航栏条目的if-then-else组合,但这非常混乱。所以
php大师,我怎样才能最好地编写单个包含文件?
I can turn the include file into php code and have a whole mess of
if-then-else combos for each nav bar entry, but that''s pretty messy. So
php gurus, how can I best code a single include file?
str_replace / preg_replace,我想。 :)
您可以简单地解析HTML文件,并使用纯文本或任何您想要的内容将锚点替换为活动的
页面。但是不要问我
regexps ......;)
干杯
Mike
str_replace/preg_replace, I suppose. :)
You can simply parse your HTML file and replace the anchors to the active
page with pure text or whatever you wish. But don''t ask me about
regexps... ;)
Cheers
Mike
jdub写道:
我厌倦了不断更改我们众多
顶级页面上的导航栏,所以我终于使用了包含一个仅限html的文件。
这是一个片段:
< div class =" navleft">
< a href =" home。 php"> Home< / a>
< div class =" navspacer">< / div>
< a href =" newitems.php">< b>新商品!< / b>< / a>
< div class =" navspacer">< / div>
< a href =" items1.php">第1项< / a>
< a href =" items2.php">第2项< / a>
< a href =" items3.php">第3项< / a>
< div class =" navspacer">< / div>
< a href =" blah blah"> b lah blah< / a>
< a href =" contact.php">< b>与我们联系!< / b>< / a>
< / div>
现在我想修改导航栏,使活动页面不是可点击的链接,并以不同的方式显示。例如,当项目
1页面处于活动状态时,导航栏应该具有
< div id =" activeselection"> items 1< / div>
而不是href行。
我可以将包含文件转换为php代码,并且每个导航栏条目都有一堆
if-then-else组合,但这非常混乱。
那么php大师,我怎样才能最好地编写单个包含文件?
I got tired of constantly changing the navigation bar on our numerous
top-level pages, so I finally used an include of an html-only file.
Here''s a snippet:
<div class="navleft">
<a href="home.php">Home</a>
<div class="navspacer"></div>
<a href="newitems.php"><b>New Items!</b></a>
<div class="navspacer"></div>
<a href="items1.php">items 1</a>
<a href="items2.php">items 2</a>
<a href="items3.php">items 3</a>
<div class="navspacer"></div>
<a href="blah blah">blah blah</a>
<a href="contact.php"><b>Contact Us!</b></a>
</div>
Now I want to modify the nav bar so that the active page is not
a clickable link and appears differently. E.g., when the items
1 page is active, the nav bar should have
<div id="activeselection">items 1</div>
instead of the href line.
I can turn the include file into php code and have a whole mess of
if-then-else combos for each nav bar entry, but that''s pretty messy.
So php gurus, how can I best code a single include file?
我认为你甚至不需要HTML。假设你有这个标签 -
分隔的文本文件''menu.txt'':
home.php主页
newitems.php< b>新商品!< / b>
items1.php商品1
items2。 php项目2
items3.php项目3
blah blah blah blah
contact.php< b>联系我们! < / b>
项目之间的空行意味着这些项目之间应该有间隔
。
现在你可以这样做:
I think you don''t even need HTML. Let''s say you have this tab-
delimited text file called ''menu.txt'':
home.php Home
newitems.php <b>New Items!</b>
items1.php items 1
items2.php items 2
items3.php items 3
blah blah blah blah
contact.php <b>Contact Us!</b>
An empty line between items means that there should be a spacer
between those items.
Now you can do something like this:
running = strtolower(pathinfo(
running = strtolower(pathinfo(
这篇关于帮助编码导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!