使用php添加活动类后,链接无法完全正常工作

时间:2022-11-07 03:52:14

I'm using php to add active link state to my navigation menu which is shared dynamically across all my website pages. But when I go to other links from homepage it works fine but when I go back to homepage its give me "object not found" error.

我正在使用php将活动链接状态添加到我的导航菜单中,该菜单在我的所有网站页面中动态共享。但是,当我从主页上转到其他链接时,它工作正常,但当我回到主页时,它给我“找不到对象”错误。

<!--start vertical menu-->
<?php 
$index="menu-items";
$top_albums_default="menu-items";
$Topartists="menu-items";
$Toplists="menu-items";
$Charts="menu-items";
$menuLinkid=basename($_SERVER['PHP_SELF'],".php");
if($menuLinkid=="index"){
    $index='active';
}else if ($menuLinkid=="top_albums_default"){
    $top_albums_default='active';
}else if ($menuLinkid=="Topartists"){
    $Topartists='active';
}else if ($menuLinkid=="Toplists"){
    $Toplists='active';
}else if ($menuLinkid=="Charts"){
    $Charts='active';
}
?>
<div id="vertical-menu">
    <!--<h2 class="logo">LOGO</h2>-->
    <img class="logo" src="../Graphics/icons/logo.png" alt="LOGO"/>
    <h6 class="logo-desc">Arcade Music Repository</h6>
    <ul class="menu-items">
        <li>
            <a class="<?php echo $index; ?>" href="index.php" ><i class="arcd-archive" ></i></br>Browse</a>                            
        </li>
        <li>
            <a class="<?php echo $top_albums_default; ?>" href="Top-albums/top_albums_default.php"><i class="arcd-music97"></i></br>Top albums</a>                            
        </li>
        <li>
            <a href="../Top-artists/top-artists_default.php"><i class="arcd-microphone52"></i></br>Top artists</a>                            
        </li>
        <li>
            <a href="../Top-lists/top-lists_default.php"><i class="arcd-numbered8"></i></br>Top lists</a>
        </li>
        <li>
            <a href="../Charts/Charts_default.php"><i class="arcd-rising9"></i></br>Charts</a>
        </li>                        
    </ul>
</div>
<script type="text/javascript" src="../js/jquery-1.11.3.min.js">  </script>   

Please check this in video

请在视频中查看此内容

Here is my site folders structure

这是我的站点文件夹结构

1 个解决方案

#1


You are missing a forward slash on your homepage link.

您在主页链接上缺少正斜杠。

Make it like this:

像这样:

            <ul class="menu-items">
                <li>
                    <a class="<?php echo $index; ?>" href="/index.php" ><i class="arcd-archive" ></i></br>Browse</a>                            
                </li>

#1


You are missing a forward slash on your homepage link.

您在主页链接上缺少正斜杠。

Make it like this:

像这样:

            <ul class="menu-items">
                <li>
                    <a class="<?php echo $index; ?>" href="/index.php" ><i class="arcd-archive" ></i></br>Browse</a>                            
                </li>