我已经创建了一个由php的导航菜单。
1)我需要帮助如何更改当前页面的链接类。我的意思是例如,当主页打开时,链接应该像class =" bla bla current"
2)是否有任何建议,可以更好地链接到该按钮。这是代码
<?php
require_once('../config.php');
$sql= "SELECT * FROM veri_kategori";
foreach ($dbh->query($sql) as $row)
{
echo "<li class="dropdown"><a href="".$row["link_tr"]."" class="dropdown-toggle">".$row["tr"]."</a></li>";
}
?>
尝试以下解决方案:
<?
require_once('../config.php');
// Get the current page.
$pag = $_GET['pag'];
if (isset($pag)) {
if ($page == 'about') {
// Redirect or include your page.
} else if ($page == 'contact') {
// Redirect or include your page.
}
} else {
// Redirect or include your home page.
}
$sql = "SELECT * FROM veri_kategori";
foreach ($dbh->query($sql) as $row) {
// Set default class.
$class = "dropdown-toggle";
// If home page, set another class.
if (!isset($pag)) {
$class = "bla bla CURRENT";
}
echo "<li class="dropdown"><a href="index.php?pag={$row["link_tr"]}" class="{$class}">{$row["tr"]}</a></li>";
}
?>