It looks like you're new here. If you want to get involved, click one of these buttons!
$nav = array();
$nav['home'] = array('label'=>'Home');
$nav['events'] = array('label'=>'Events');
$nav['gallery'] = array('label'=>'Gallery');
$nav['feedback'] = array('label'=>'Feedback');
$nav['contact'] = array('label'=>'Contact Us');
echo fuel_nav(array('container_tag_id' => 'topmenu', 'item_id_prefix' => 'topmenu_', 'pre_render_func' => 'my_menu_func', 'active_class'=>'on'));
$nav = array();
$cats = fuel_model('categories', array('find' => 'all', 'where' => array('published' => 'yes'), 'name asc'));
$CI->load->model('sub_categories_model');
$CI->load->model('categories_to_members_model');
foreach($cats as $cat):
$id = $cat->id;
$title = $cat->name;
$catUrl = $cat->url;
$numOfSubCats = $CI->sub_categories_model->record_count(array('cat_id'=>$id));
$total = $CI->categories_to_members_model->record_count(array('category_id'=>$id));
$label = $title . ' (' . $total . ')';
$nav['members/' . $catUrl] = array('label'=>$label, 'id'=>$title);
if($numOfSubCats != 0):
$subCats = fuel_model('sub_categories', array('find' => 'all', 'where' => array('cat_id' => $id), 'name asc'));
foreach($subCats as $sub):
$subCatId = $sub->id;
$url = $sub->url;
$subName = $sub->name;
$subTotal = $CI->categories_to_members_model->record_count(array('category_id'=>$id, 'sub_cat_id'=>$subCatId));
if(empty($subTotal)) $subTotal = 0;
$subLabel = $subName . ' (' . $subTotal . ')';
$nav['members/' . $title . '/' . $url] = array('label' => $subLabel, 'parent_id' => 'members/' . $catUrl, 'id'=>$subCatId);
endforeach;
endif;
endforeach;
echo fuel_nav(array('file' => 'sidemenu', 'container_tag_id' => 'accordion', 'container_tag_class' => 'accordion', 'active_class' => 'on'));
<ul id="accordion" class="accordion">
<li class="first"><a href="http://localhost/clarenssaNewFuel/members/accommodation" title="Accommodation (5)">Accommodation (5)</a>
<ul>
<li class="first"><a href="http://localhost/clarenssaNewFuel/members/Accommodation/bb" title="B & B (0)">B & B (0)</a></li>
<li><a href="http://localhost/clarenssaNewFuel/members/Accommodation/guesthouse" title="Guesthouse (2)">Guesthouse (2)</a></li>
<li><a href="http://localhost/clarenssaNewFuel/members/Accommodation/selfcatering" title="Self-Catering (2)">Self-Catering (2)</a></li>
<li class="last"><a href="http://localhost/clarenssaNewFuel/members/Accommodation/hotel" title="Hotel (1)">Hotel (1)</a></li>
</ul>
</li>
<li><a href="http://localhost/clarenssaNewFuel/members/healthbeauty" title="Health & Beauty (2)">Health & Beauty (2)</a></li>
<li><a href="http://localhost/clarenssaNewFuel/members/outdoors" title="Outdoors (2)">Outdoors (2)</a></li>
<li><a href="http://localhost/clarenssaNewFuel/members/food" title="Food (0)">Food (0)</a></li>
<li class="on"><a href="http://localhost/clarenssaNewFuel/members/retail" title="Retail (2)">Retail (2)</a></li>
<li class="last"><a href="http://localhost/clarenssaNewFuel/members/hungrythirsty" title="Hungry or Thirsty? (1)">Hungry or Thirsty? (1)</a></li>
</ul>
$nav['members/' . $title . '/' . $url] = array('label' => $subLabel, 'parent_id' => 'members/' . $catUrl, 'id'=>$subCatId);
$nav['members/' . $title . '/' . $url] = array('label' => $subLabel, 'parent_id' => 'members/' . $catUrl, 'id'=>$subCatId);
Comments
For your last snippet, It's just 'parent' not 'parent_id'.
I've not had a problem losing the active class before, don't suppose your browser is caching the page? Try a force refresh just to be sure.
In the sidemenu, I think the problem is in the jquery I am using, investigating.
And you actually do want 'parent_id' for the last snippet.
Array ( [home] => Array ( [label] => Home ) [events] => Array ( [label] => Events ) [gallery] => Array ( [label] => Gallery ) [tourismforum] => Array ( [label] => Tourism Forum ) [feedback] => Array ( [label] => Feedback ) [contact] => Array ( [label] => Contact Us ) )
The URI location is:
http://localhost/clarenssaNewFuel/home
unless URI location is something different than the url?I have added in the header_block view:
echo fuel_nav(array('container_tag_id' => 'topmenu', 'item_id_prefix' => 'topmenu_', 'pre_render_func' => 'my_menu_func', 'active_class'=>'on', 'active' => uri_segment(1)));
My url:
http://localhost/clarenssaNewFuel/home
No active class.
The active class is not being added to the menu when I browse to:
http://localhost/clarenssaNewFuel/home <ul id="topmenu"> <li id="topmenu_home" class="first on"><a href="http://localhost/clarenssaNewFuel/home" title="Home"><span>Home</span></a></li>
My css:
ul#topmenu li a:hover, ul#topmenu li a.active { background-position:0% -50px; }
'active_class'=>'active'
but the problem is the active class is being added to the list item, I need it to be added to the link item.Is there a way to add the class to the link and not the list item in the call to the fuel_nav?
Could you not just change your css?
ul#topmenu li a:hover, ul#topmenu li.active a{ background-position:0% -50px; }
If anybody is interested in the solution.
My old html looked like this:
<ul id="topmenu"> <li><a href="#" class="active"><span>Home</span></a></li> <li><a href="#"><span>About</span></a></li> ... </ul>
That chaned to:
<ul id="topmenu"> <li class="active"><div><a href="#">Home</a></div></li> <li><div><a href="#">About</a></div></li> ... </ul>
The old css:
ul#topmenu li { display: inline; margin: 0; padding: 0; } ul#topmenu li a { float: left; background: url("../images/template/nav/navleft.gif") no-repeat left top; margin: 0; padding: 0 0 0 4px; text-decoration: none; } ul#topmenu li a span { float: left; display: block; background: url("../images/template/nav/navright.gif") no-repeat right top; padding: 10px 15px 6px 6px; color: #597882; } ul#topmenu li a span {float:none; font-weight: bold;} ul#topmenu li a:hover span, ul#topmenu li.active a { color:#FFF; } ul#topmenu li a:hover, ul#topmenu li.active { background-position:0% -50px; } ul#topmenu li a:hover span, ul#topmenu li.active a span { background-position:100% -50px; }
The new css:
ul#topmenu li { float: left; margin:0; padding: 0 0 0 4px; height: 32px; background:url("../images/template/nav/navleft.gif") no-repeat left top; } ul#topmenu li div { background: url("../images/template/nav/navright.gif") no-repeat right top; padding: 10px 15px 6px 6px; height: 16px; } ul#topmenu li div a { float: left; display: block; color: #597882; text-decoration: none; font-weight: bold; } /* Commented Backslash Hack hides rule from IE5-Mac \*/ ul#topmenu li div {float:none; font-weight: bold;} /* End IE5-Mac hack */ ul#topmenu li.active div a, ul#topmenu li:hover div a { color:#FFF; } ul#topmenu li:hover, ul#topmenu li.active { background-position:0% -50px; } ul#topmenu li:hover div, ul#topmenu li.active div { background-position:100% -50px; }
Css:
ul#topmenu li { display: inline; margin: 0; padding: 0; } ul#topmenu li a { float: left; background: url("../images/template/nav/navleft.gif") no-repeat left top; margin: 0; padding: 0 0 0 4px; text-decoration: none; } ul#topmenu li a span { float: left; display: block; background: url("../images/template/nav/navright.gif") no-repeat right top; padding: 10px 15px 6px 6px; color: #597882; } ul#topmenu li a span {float:none; font-weight: bold;} ul#topmenu li a:hover span, ul#topmenu li.active a span { color:#FFF; } ul#topmenu li a:hover, ul#topmenu li.active a { background-position:0% -50px; } ul#topmenu li a:hover span, ul#topmenu li.active a span { background-position:100% -50px; }
Calling to fuel_nav:
First try:
echo fuel_nav(array('container_tag_id' => 'topmenu', 'item_id_prefix' => 'topmenu_', 'pre_render_func' => 'my_menu_func'));
Second try:
echo fuel_nav(array('container_tag_id' => 'topmenu', 'item_id_prefix' => 'topmenu_', 'pre_render_func' => 'my_menu_func', 'active_class' => 'active'));
The menu that is being rendered:
<ul id="topmenu"> <li id="topmenu_home" class="first"><a href="http://localhost/clarenssaNewFuel/home" title="Home"><span>Home</span></a></li> <li id="topmenu_events"><a href="http://localhost/clarenssaNewFuel/events" title="Events"><span>Events</span></a></li> <li id="topmenu_gallery"><a href="http://localhost/clarenssaNewFuel/gallery" title="Gallery"><span>Gallery</span></a></li> <li id="topmenu_clarenstourismforum"><a href="http://localhost/clarenssaNewFuel/clarenstourismforum" title="Tourism Forum"><span>Tourism Forum</span></a></li> <li id="topmenu_feedback"><a href="http://localhost/clarenssaNewFuel/feedback" title="Feedback"><span>Feedback</span></a></li> <li id="topmenu_contact" class="last"><a href="http://localhost/clarenssaNewFuel/contact" title="Contact Us"><span>Contact Us</span></a></li> </ul>
Where is the active class on the home item? Why is it not there? the url:
http://localhost/clarenssa/home
The nav array was:
$nav['home'] and not $nav['Home']
Changed that, now at last everything works.
Thank you very much for all the help.