Hey I have question about Dynamic menu which is created in php. Code is from stackoverflow, what I want is to get my parent styled with red color if children of those parent is selected, here is code:
$menu = Array(
Array(
'title' => 'Home',
'link' => 'a'
),
Array(
'title' => 'Parent',
'link' => 'b',
'children' => Array(
Array(
'title' => 'Sub 1',
'link' => 'c'
),
Array(
'title' => 'Sub 2',
'link' => 'd'
),
)
)
);
function buildMenu($menuArray)
{
foreach ($menuArray as $node)
{
$selected = ($node['link']== $_GET['menu']) ? $selected = 'style="color: red;"' : null;
echo "<li ".$selected."><a href='?menu=".$node['link']."'/>" . $node['title'] . "</a>";
if ( ! empty($node['children'])) {
echo "<ul>";
buildMenu($node['children']);
echo "</ul>";
}
echo "</li>";
}
}
buildMenu($menu);
So how it needs to go:
Home
Parent - selected
Sub 1 - selected
Sub 2
or
Home
Parent - selected
Sub 1
Sub 2 - selected
Hope someone understand what i want? If my children under parent is selected also parent needs to be selected.