php - 创建一个突出显示当前选项卡的 php 菜单

标签 php html css menu

所以我在 php 文件中有一个菜单,看起来像这样(这是整个文件。我对 PHP 完全陌生。)

菜单.php:

<li id="current"><a href="#"><span>Home</span></a></li> 
<li><a href="http://blog.me.net/"><span>Blog</span></a></li> 
<li><a href="http://www.me.net/R"><span>Results</span></a></li> 
<li><a href="http://www.me.net/P"><span>Pictures</span></a></li> 
<li><a href="http://www.me.net/O.html"><span>Our Location</span></a></li>

现在在我的页面中我这样做(index.php):

<div id="tabs1" >
    <ul>
        <!-- CSS Tabs -->
        <?php include("menu.php"); ?>
    </ul>
</div>

所以我想做的就是将上面的行更改为:

<?php include("menu.php?current=pictures"); ?>

这将使事件选项卡成为图片选项卡。我该怎么做?

最佳答案

你也可以试试这个:

你的 php 脚本

<?php
    $selected = "pictures";
    $current_id = ' id="current"';
    include "menu.php";
?>

这是你的菜单:

<ul>
<li <?php if ($selected == "pictures") print $current_id; ?>><a href="#"><span>Home</span></a></li> 
<li <?php if ($selected == "blog") print $current_id; ?>><a href="http://blog.me.net/"><span>Blog</span></a></li> 
<li <?php if ($selected == "home") print $current_id; ?>><a href="http://www.me.net/R"><span>Results</span></a></li> 
<li <?php if ($selected == "me") print $current_id; ?>><a href="http://www.me.net/P"><span>Pictures</span></a></li> 
<li <?php if ($selected == "contacts") print $current_id; ?>><a href="http://www.me.net/O.html"><span>Our Location</span></a></li>
</ul>

关于php - 创建一个突出显示当前选项卡的 php 菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2216453/

相关文章:

php - 如何使用 PHP 调整高分辨率图片的大小

php - 从 App Engine 连接到 Cloud SQL 不起作用

html - Bootstrap 高级下拉搜索

css - 如何在不将 border-width 添加到元素的整个宽度的情况下使用 css 为任何元素提供边框?

php - 这个 MySQL IN 子句中的负值有什么问题?

php - 从 Woocommerce 3.4+ 中“我的帐户编辑地址”字段中删除(可选)文本

html - 如何在完全响应的情况下在中心执行此 Bootstrap 搜索框?

html - 将图像左对齐放在固定的导航栏上

html - HTML 和 CSS 中基于网格的布局问题

css - Chrome Firefox 上的网站延迟,但不是 Safari