使导航动态化

时间:2015-03-30 16:08:07

标签: php html twitter-bootstrap

我想让我的导航变得动态,但我有一些问题。这是我的代码。

<?php 
	if (stristr($_SERVER["SCRIPT_NAME"], "index.php")) {
		echo '<li class="active">
			 <a href="index.php">
        <span class="meta">
            <span class="text">HOME</span>
            <!--<span class="caret"></span>-->
        </span>
    </a>
</li>';
	} else{
		echo '<li>
			 <a href="index.php">
        <span class="meta">
            <span class="text">HOME</span>
            <!--<span class="caret"></span>-->
        </span>
    </a>
</li>';
	}
?>
  
<?php 
	if (stristr($_SERVER["SCRIPT_NAME"], "services.php")) {
		echo '<li class="dropdown active">
		<a href="#" class="dropdown-toggle " data-toggle="dropdown">
			<span class="meta">
            <span class="text">SERVICES</span>
            <span class="caret"></span>
        </span>
    </a>
   <ul class="dropdown-menu">
        <li><a href="#">Service A</a></li>
        <li><a href="#">Service B</a></li>
        <li><a href="#">Service C</a></li>
        <li><a href="#">Service D</a></li>
    </ul>
</li>';
	} else{
		echo '<li class="dropdown">
		<a class="dropdown-toggle " data-toggle="dropdown">
			<span class="meta">
            <span class="text">SERVICES</span>
            <span class="caret"></span>
        </span>
    </a>
    <ul class="dropdown-menu">
        <li><a href="#">Service A</a></li>
        <li><a href="#">Service B</a></li>
        <li><a href="#">Service C</a></li>
        <li><a href="#">Service D</a></li>
    </ul>
</li>';
	}
?>
   
<?php 
	if (stristr($_SERVER["SCRIPT_NAME"], "data-catalog.php")) {
		echo '<li class="active">
		<a href="data-catalog.php">
        <span class="meta">
            <span class="text">DATA CATALOG</span>
            <!--<span class="caret"></span>-->
        </span>
    </a>
</li>';
	} else{
		echo '<li>
		<a href="data-catalog.php">
        <span class="meta">
            <span class="text">DATA CATALOG</span>
            <!--<span class="caret"></span>-->
        </span>
    </a>
</li>';
	}
?>
    
<?php 
	if (stristr($_SERVER["SCRIPT_NAME"], "about.php")) {
		echo '<li class="active">
		 <a href="about.php">
        <span class="meta">
            <span class="text">ABOUT US</span>
            <!--<span class="caret"></span>-->
        </span>
    </a>
</li>';
	} else{
		echo '<li>
		 <a href="about.php">
        <span class="meta">
            <span class="text">ABOUT US</span>
            <!--<span class="caret"></span>-->
        </span>
    </a>
</li>';
	}
?>
   
<?php 
	if (stristr($_SERVER["SCRIPT_NAME"], "contact.php")) {
		echo '<li class="active">
		<a href="contact.php">
        <span class="meta">
            <span class="text">CONTACT US</span>
            <!--<span class="caret"></span>-->
        </span>
    </a>
</li>';
	} else{
		echo '<li>
		<a href="contact.php">
        <span class="meta">
            <span class="text">CONTACT US</span>
            <!--<span class="caret"></span>-->
        </span>
    </a>
</li>';
	}
?>
    

运行后,我意识到在主页上,服务列表成功下降,但当我在其他页面上时它没有这样做。有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

我认为代码及其结构是完美的。代码没有绝对的错误。刚上传文件到网上,一切都很完美。我检查了插件和所有,我意识到文件只需要在互联网上运行顺利。