PHP导航菜单 [英] PHP navigation menu

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

问题描述

我正在做一个网站作为大学作业的一部分。我有一个导航列表,我的页面使用CSS样式,所以当一个页面被选中时,链接显示为粗体,旁边有一个图像。我想保持这个菜单的样式,但将这部分的html代码移动到一个.php文件,只是包括它在每个页面上的代码重用。

I am making a website as part of a college assignment. I have a navigation list for my pages styled using CSS so when a page is selected the link appears bold with an image beside. I was wanting to keep the style of this menu however move this part of the html code to a .php file and just include it on each of the pages for code re-use.

很容易做,然而,因为我有一个类设置,以确定选择哪个页面改变链接的外观我将如何传递这个PHP文件 - 是可能吗?

Easy enough to do however because I have a class set to determine which page is selected an change the look of the link how would I go about passing this to the PHP file - Is it possible?

下面的代码段...

当前HTML列表:

<ul>
    <li class="selected"><a href="index.html">Home</a></li>
    <li><a href="login.html">Members Login</a></li>
    <li><a href="#">Music Categories</a></li>
    <li><a href="#">Contact Us</a></li>
</ul>

所选页面的CSS:

nav ul li.selected a
{
color:#fff;
font-weight:bold;
background:url(images/music_note2.png) center left no-repeat;
}

是否有某种代码我可以使用pass的页面名称? Appologies我从来没有使用过php。不确定是否重要,但后来我还需要根据用户是否登录隐藏或显示菜单上的某些链接

Is there some sort of code I can use the pass the name of the page? Appologies I have never used php. Not sure if it matters but later on I will need to also hide or show certain links on the menu depending on whether the user is logged in

推荐答案

你可以在css中做,如果你想。只需向每个页面的 body 添加一个类,例如 home 回家, code>到联系人等。

You can do it in just css if you want to. Just add a class to the body of every page like home to home, contact to contact, etc.

<body class="home">    // for home page
   ...

<body class="contact">    // for contact page
   ...

例如:

<ul>
    <li class="home"><a href="index.html">Home</a></li>
    <li class="login"><a href="login.html">Members Login</a></li>
    <li class="music"><a href="#">Music Categories</a></li>
    <li class="contact"><a href="#">Contact Us</a></li>
</ul>

现在,您可以突出显示活动菜单项,如:

Now you can highlight your active menu item like:

.home .home a,
.login .login a,
.music .music a,
.contact .contact a {
  color:#fff;
  font-weight:bold;
  background:url(images/music_note2.png) center left no-repeat;
}

这篇关于PHP导航菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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