Welcome Guest, Not a member yet? Register   Sign In
How to highlight current page in menu item?
#1

[eluser]qpixo[/eluser]
I have a menu which has generated dynamically from database. Now I want to highlight current page in menu item but when I do that all my current menu items dissappear suddently. Don't understand why?

Noticed when using $this->uri->segment(1) caused my menu dissappear.

Does anyone know how to make it works?



In my View file:

Code:
<div id="menu">
         <ul>
            &lt;?php foreach ($tabMenu as $item) : ?&gt;
                &lt;?php echo buildListItem($item); ?&gt;
            &lt;?php endforeach; ?&gt;    
        </ul>
    </div>


In my Helper file:

Code:
function buildListItem($item) {
$urlItemName = url_title($item->name, 'dash', TRUE);
$urlCatID = ($item->cat_id);
$url = base_url() . $urlItemName. "/". $urlCatID;

// item name is blog, add target into it
if ($urlItemName == 'blog') {
    $blog = "http://www.tumblr.com";
    return "<li><a href='" . $blog . "' target='_blank'>" . strtoupper($item->name) . "</a></li>";
} else {
    return "<li class='". isSelected($item).  "'><a href='" . $url . "'>" . strtoupper($item->name) . "</a></li>";
}
}

function isSelected($item) {
$urlItemName = url_title($item->name, 'dash', TRUE);

if ($this->uri->segment(1) === $urlItemName) {
    return 'menu_active';
} else {
    return '';
}
}
#2

[eluser]handoyo[/eluser]
Hi qpixo,what is the solution?Thanks




Theme © iAndrew 2016 - Forum software by © MyBB