Navigation Usability
  Home arrow Navigation Usability arrow Page 3 - Advanced Bulleted-List Menu
Try It Free
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
NAVIGATION USABILITY

Advanced Bulleted-List Menu
By: notepad
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2005-05-06

    Table of Contents:
  • Advanced Bulleted-List Menu
  • Menu Layout
  • Preserving State Without Cookies
  • Adding CSS
  • Adding JavaScript
  • Drawing Our Menu
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Try It Free
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Advanced Bulleted-List Menu - Preserving State Without Cookies


    (Page 3 of 7 )

    I've never had a problem with cookies, and I really don't understand why people feel like it is an invasion of privacy. I mean, my website is my house. Do you think I want you walking around my house without me knowing you're there, and what you're doing? NO. There are other ways of logging the same activity and the only difference is that it's less convenient for the end user. Still, a lot of people disable cookies.

    The following function is my slightly modified version of a function contributed by Mark Meves that I found in the PHP manual. It has the same functionality as array_search(), with the added ability to search multi-dimensional arrays (which is what we're working with). The return value will be an array, containing each key leading up to the position of the needle we're searching for.

    <?php
    function array_search_recursive($needle$haystack) {
        
    $pos null;
        
    $keys array_keys($haystack);
        while(!
    $pos &amp;&amp; (list($garbage$value)=each($keys))) {
            if(
    is_scalar($haystack[$value])) {
                if(
    $haystack[$value] === $needle)
                    
    $pos[] = $value;
            } elseif(
    is_array($haystack[$value])) {
                if(
    $pos array_search_recursive($needle$haystack[$value]))
                    
    array_unshift($pos$value);
            }
        }
        return 
    $pos;
    }
    ?>

    If you have any questions about the functions used in the above code, feel free to consult the PHP manual. The whole idea here is that if we determine what page we're on, we can then see if that page exists within our $menu array. If it does exist, then we'll be able to instruct our menu to open up to that location. For example, we'll call the above function as follows.

    <?php
    $base 
    basename($_SERVER['PHP_SELF']);
    $self = isset($_SERVER['QUERY_STRING']) ? $base.'?'.$_SERVER['QUERY_STRING'] : $base;
    $preserve array_search_recursive($self$menu);
    ?>

    The above check assumes that all of our menu pages are being stored in the local directory, hence basename(). You may need to alter this bit depending on how your "targets" are stored. For example, if you're including diretory paths then remove the basename function, or if you're including full http:// addresses then try $_SERVER['HTTP_REFERER'].

    We now have an array, $preserve, which contains each key leading up to the page we're currently viewing. You should now understand why having unique menu titles and targets is important. If we had any duplicate names, then we might accidentally instruct our menu to open up to more than one location. Sure, we could solve this trivial problem by re-organizing how our $menu array is laid out, but then that just makes things less readable and more complex than they have to be. Are you stingy cookie blockers happy!?

    More Navigation Usability Articles
    More By notepad


       · I receive this error:Parse error: parse error, unexpected...
       · check that the menu array is layed out right using the print_r code. if not,...
       · So, dont laugh me..uhh, how can i define the pages data in the blist_menu.php,...
       · Hey notepad why didn't you put up a working example? I don't mean to be a pain in...
       · How can i modify the link target? can i use &quot;iframe&quot; tag in the...
       · finally i fucked up the target&quot;=main&quot;. the right example is a...
       · try maybe escaping some parts of the url like ? etc., that might be the problem I...
       · You're a contract hacker and you make these n00b menues? Lol shame on you!Btw,...
       · just put an ) at the end of the wole array and keep doing that til the error is...
       · if u now put in a link u get a button!!...
       · if u now put in a link u get a button!!...
       · array('Menu One'=&gt;array('Page One'=&gt;'urlinkhere.php', ...
       · Hey,This is a cool tutorial and very useful,but why not let us know how to fetch...
       · Hey,This is a cool tutorial and very useful,but why not let us know how to fetch...
     

    NAVIGATION USABILITY ARTICLES

    - Advanced Bulleted-List Menu
    - Using Multiple Pages for Navigation





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway