【问题标题】:Highlight current page in menu in php-header在 php-header 的菜单中突出显示当前页面
【发布时间】:2019-10-27 04:22:12
【问题描述】:

在我的 php-header 文档中,我希望能够突出显示用户所在的当前页面,以防止混淆。

问题是,我使用了 if(isset()) 函数来隐藏/显示导航链接,具体取决于用户是否登录。

但是如何突出显示用户点击的页面?我想我必须在 if(isset()) 函数的 php-tags 中的某处包含一些 javascript,然后将其连接到 css 中的活动类,还是我错了?

<?php
    session_start();
?>
<!DOCTYPE html>
<html>
    <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>DreamcarZ</title>
            <link rel="stylesheet" href="css/style.css" type="text/css">
            <link href="https://fonts.googleapis.com/css?family=Ubuntu+Condensed&display=swap" rel="stylesheet">
    </head>
    <body>
        <div class="header">

            ​<div class="topnav">
                <div class="logo-container">
                    <h1>Dreamcar<span>Z</span></h1>
                </div>
                    <?php
                        if(isset($_SESSION['userId'])){
                            echo '<a href="index.php">Home</a>
                                <a href="exclusive_cars.php">Collection</a>
                                <a href="om_oss.php">About</a>
                                <a href="#contact">Contact</a>';
                        }
                        else {
                            echo '<a href="index.php">Home</a>
                                <a href="om_oss.php">About</a>
                                <a href="#contact">Contact</a>';
                        }
                    ?>

                <div class="login-container">
                    <?php
                        if(isset($_SESSION['userId'])){
                            echo '<form action="includes/logout.inc.php" method="post">
                            <button type="submit" name="logout-submit">Logout</button>
                            </form>';
                        }
                        else {
                            echo '<form action="includes/login.inc.php" method="post">
                            <input type="text" name="mailuid" placeholder="Username...">
                            <input class="inpt-pwd" type="password" name="pwd" placeholder="Password...">
                            <button type="submit" name="login-submit">Login</button>
                            <a class="signup" href="signup.php">Signup</a>
                            </form>';
                        }
                    ?>
                </div>

            </div>

        </div>

【问题讨论】:

    标签: php html css


    【解决方案1】:

    您需要创建一个“活动”类,这将使导航元素看起来是独一无二的。 然后,在每个页面上创建一个 php 变量作为标志值,特定于每个页面,然后使用 if 子句将该“活动”类分配给 nav 元素。

    更多详情请参考这篇文章: https://www.sitepoint.com/community/t/how-add-active-state-to-the-navigation-menu-with-php/7356

    谢谢!

    【讨论】:

    • 问题是,我需要使用某种脚本,老师已经告诉我了。对于我遇到的情况,是否不可能使用脚本?
    猜你喜欢
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 2011-10-27
    • 2016-02-25
    • 2022-01-05
    相关资源
    最近更新 更多