add current page highlight feature

This commit is contained in:
2025-04-11 07:22:18 +04:00
parent 19fc787f68
commit c7124f89cb
3 changed files with 147 additions and 68 deletions
+15 -4
View File
@@ -4,11 +4,20 @@
<img src="img/logo.png" alt="kaubuntu.re">
</a>
<?php
// Détecter la page courante et ses paramètres
$currentPage = basename($_SERVER['PHP_SELF']);
$currentCategoryId = isset($_GET['id']) ? intval($_GET['id']) : null;
$currentQuery = isset($_GET['q']) ? trim($_GET['q']) : '';
$isTagSearch = !empty($currentQuery) && substr($currentQuery, 0, 1) === '#';
$currentTag = $isTagSearch ? substr($currentQuery, 1) : '';
?>
<nav class="sidebar-nav">
<a href="index.php" class="nav-item" data-title="Accueil">
<a href="index.php" class="nav-item <?php echo ($currentPage === 'index.php') ? 'active' : ''; ?>" data-title="Accueil">
<i class="fas fa-home"></i> <span>Accueil</span>
</a>
<a href="direct.php" class="nav-item" data-title="Direct">
<a href="direct.php" class="nav-item <?php echo ($currentPage === 'direct.php') ? 'active' : ''; ?>" data-title="Direct">
<i class="fas fa-broadcast-tower"></i> <span>Direct</span>
</a>
@@ -40,8 +49,9 @@
];
foreach (PRIORITY_CATEGORIES as $id => $name) {
$isActive = ($currentPage === 'categories.php' && $currentCategoryId === $id);
$icon = isset($categoryIcons[$id]) ? $categoryIcons[$id] : 'fas fa-folder';
echo '<a href="categories.php?id=' . $id . '" class="nav-item" data-title="' . htmlspecialchars($name) . '">';
echo '<a href="categories.php?id=' . $id . '" class="nav-item ' . ($isActive ? 'active' : '') . '" data-title="' . htmlspecialchars($name) . '">';
echo '<i class="' . $icon . '"></i> <span>' . htmlspecialchars($name) . '</span>';
echo '</a>';
}
@@ -58,8 +68,9 @@
if (defined('IMPORTANT_TAGS') && !empty(IMPORTANT_TAGS)):
foreach (IMPORTANT_TAGS as $tag):
$encodedTag = urlencode('#' . $tag);
$isActive = ($isTagSearch && strtolower($currentTag) === strtolower($tag));
?>
<a href="recherche.php?q=<?php echo $encodedTag; ?>" class="tag-item" data-title="<?php echo htmlspecialchars($tag); ?>">
<a href="recherche.php?q=<?php echo $encodedTag; ?>" class="tag-item <?php echo $isActive ? 'active' : ''; ?>" data-title="<?php echo htmlspecialchars($tag); ?>">
<i class="fas fa-hashtag tag-icon"></i> <span><?php echo htmlspecialchars($tag); ?></span>
</a>
<?php