Standart constructor menu ../index.php?a=admin&b=manage_menus is good!
To ensure that the active link works correctly in the created menus.
Tunning code function:
1. Open ../sources/misc/skin.php (before backup this script)
2. Replace full function "// BUILD MENUS" to
To ensure that the active link works correctly in the created menus.
Tunning code function:
1. Open ../sources/misc/skin.php (before backup this script)
2. Replace full function "// BUILD MENUS" to
PHP:
// BUILD MENUS
$res = $DB->query("SELECT * FROM {$CONF['sql_prefix']}_menu ORDER BY sort ASC", __FILE__, __LINE__);
$list = [];
while ($r = mysqli_fetch_object($res)) {
$menu_id = (int)$r->menu_id;
$id = (int)$r->id;
$list[$menu_id][$id] = [
'title' => htmlspecialchars($r->title, ENT_QUOTES, 'UTF-8'),
'path' => htmlspecialchars($r->path, ENT_QUOTES, 'UTF-8'),
'target' => htmlspecialchars($r->target, ENT_QUOTES, 'UTF-8')
];
}
// Get the current 'a' parameter from GET
$current_action = filter_input(INPUT_GET, 'a', FILTER_SANITIZE_STRING) ?? '';
foreach ($list as $menu_id => $menu_items) {
$menu_id = (int)$menu_id;
$TMPL["menu-$menu_id"] = "<ul class=\"nav menu-" . htmlspecialchars((string)$menu_id, ENT_QUOTES, 'UTF-8') . "\">\n";
foreach ($menu_items as $menu_content) {
$url = $menu_content['path'];
$is_active = false;
// Parse the menu URL
$url_parts = parse_url($url);
// Check if it is the main page
if (!isset($url_parts['query']) && $current_action === '') {
$is_active = true;
}
// Check internal pages by the 'a' parameter
elseif (isset($url_parts['query'])) {
parse_str($url_parts['query'], $query_params);
if (($query_params['a'] ?? '') === $current_action) {
$is_active = true;
}
}
$active_class = $is_active ? ' class="active"' : '';
$targets = $menu_content['target'] !== '' ? ' ' . $menu_content['target'] : '';
$TMPL["menu-$menu_id"] .= '<li' . $active_class . '><a href="' . $url . '"' . $targets . '>'
. $menu_content['title'] . '</a></li>' . "\n";
}
$TMPL["menu-$menu_id"] .= '</ul>' . "\n";
}
Last edited: