I am building a CMS and I have problems with my navigation. I want to add the class active to the active item in the navigation. This would work fine if I had a page for every item, but I have other sections and links
Here is my code:
<div id="main-menu">
<?php foreach ($items as $item) : ?>
<?php $active = ''; ?>
<?php if (isset($page)) : ?>
<?php ($item->pageId === $page->id) ? $active = 'active' : $active = ''; ?>
<?php endif; ?>
<?php if ($item->link == '') : ?>
<a href="<?php echo ROOT_PATH; ?>front/site/page?x=<?php echo $item->id; ?>" class="<?php echo $active; ?>"><?php echo $item->label; ?></a>
<?php else : ?>
<a href="<?php echo $item->link; ?>" class="<?php echo $active; ?>"><?php echo $item->label; ?></a>
<?php endif; ?>
<?php endforeach; ?>
When I do not have a page, then I give the link the value provided to point to the specific section. How can I make them all to work fine?