Welcome Guest, Not a member yet? Register   Sign In
Include a menu on every page? use url helper in a class?
#4

[eluser]John_Betong[/eluser]
 
I have just written a common menu for our latest project. It checks the URL against the menu item title and if there is a match then the class changes to highlight the particular page item title.
 

Code:
// CSS file
  #navigation a.on {color:#fff}
  #navigation a.off{color:#bbb}
  #navigation a    {display:inline; background:url(/images/nav.png);text-decoration:none}

  // _top_menu.php file declated in  MY_Controller.php
<?php
  $a =    array
                (
                    'home'      => 'c_five/home',
                    'about'     => 'c_five/about',
                    'archives'  => 'c_five/archives',
                    'contact'   => 'c_five/contact',
                    'writing'   => 'c_five/writing',
                    'subscribe' => 'c_five/subscribe'
                );
    foreach($a as $title => $url):
        $toggle = strpos($this->uri->uri_string, $url) ? 'on' : 'off';
        echo anchor($url, $title, "class='$toggle'") .nbs(15);
    endforeach;                
    unset($toggle);unset($a);
//
 
 
 
edit: spelling and formatting


Messages In This Thread
Include a menu on every page? use url helper in a class? - by El Forum - 10-29-2009, 08:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB