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

2022-01-06 00:00:00 php html css menu

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

menu.php:

<li id="current"><a href="#"><span>首页</span></a></li><li><a href="http://blog.me.net/"><span>博客</span></a></li><li><a href="http://www.me.net/R"&g​​t;<span>结果</span></a></li><li><a href="http://www.me.net/P"><span>图片</span></a></li><li><a href="http://www.me.net/O.html"><span>我们的位置</span></a></li>

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

<ul><!-- CSS 标签 --><?php include("menu.php");?>

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

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

这将使活动选项卡成为图片选项卡.我该怎么做?

解决方案

你也可以试试这个:

你的php脚本

这是您的菜单:

    <li <?php if ($selected == "pictures") 打印 $current_id;?>><a href="#"><span>首页</span></a></li><li <?php if ($selected == "blog") 打印 $current_id;?>><a href="http://blog.me.net/"><span>博客</span></a></li><li <?php if ($selected == "home") 打印 $current_id;?>><a href="http://www.me.net/R"&g​​t;<span>结果</span></a></li><li <?php if ($selected == "me") 打印 $current_id;?>><a href="http://www.me.net/P"><span>图片</span></a></li><li <?php if ($selected == "contacts") 打印 $current_id;?>><a href="http://www.me.net/O.html"><span>我们的位置</span></a></li>

So I have a menu in a php file that looks like this (This is the whole file. I'm totally new to PHP.)

menu.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>

Now in my pages I do this (index.php):

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

So what I want to be able to do is change the line above to this:

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

Which would make the active tab the Pictures tab. How can I do this?

解决方案

You could also try this:

Your php script

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

this is your menu:

<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>

相关文章