This is a partial english translation of my italian blog article Un menu di navigazione superiore per Thematic completamente configurabile.
Starting from Justin Tadlock article Easy navigation menus in WordPress I’ve tried to modify his function in order to have a customizable navigation menu in Thematic with SuperFish drop-down sub-items.
This is my solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <?php // Function to create a custom navigation menu in Thematic for WordPress (http://themeshaper.com/thematic-for-wordpress/) // Author: Matteo Stagi // based on Justin Tadlock - Easy navigation menus in WordPress (http://justintadlock.com/archives/2009/01/06/easy-navigation-menus-in-wordpress) // URL: http://www.matteostagi.it/2009/menu-di-navigazione-configurabile-per-thematic // Under Creative Commons Attribution 2.5 license (http://creativecommons.org/licenses/by/2.5/) function stagi_bookmark_menu($menu) { $menu = false; $page_uri = str_replace("/", "", $_SERVER['REQUEST_URI']); $class = "page_item"; $totalbookmarksnumber = count(get_bookmarks()); $bookmarks = get_bookmarks(array('category_name' => 'menuLink', 'orderby' => 'rating')); $menu = '<div class="menu"><ul>'; foreach($bookmarks as $bookmark) : $class = " ".strtolower(str_replace(" ","-",$bookmark->link_name)); $menu .= '<li class="' . $class . '"><a href="' . $bookmark->link_url . '" title="' . $bookmark->link_description . '" rel="' . $bookmark->link_rel . '">' . $bookmark->link_name . '</a>'; $subbookmarks = get_bookmarks(array('category_name' => $bookmark->link_name, 'orderby' => 'rating')); if (count($subbookmarks)==$totalbookmarksnumber) { $menu .='</li>'; } else { $menu .='<ul>'; foreach($subbookmarks as $subbookmark) : $subclass = " ".strtolower(str_replace(" ","-",$subbookmark->link_name)); $menu .= '<li class="' . $subclass . '"><a href="' . $subbookmark->link_url . '" title="' . $subbookmark->link_description . '" rel="' . $subbookmark->link_rel . '">' . $subbookmark->link_name . '</a></li>'; endforeach; $menu .= '</ul></li>'; } endforeach; $menu .= '</ul></div>'; return $menu; } add_filter('wp_page_menu', 'stagi_bookmark_menu'); ?> |
How to use it
After putting the code inside funcions.php of your child theme you can add/move/remove menu items simply adding links in Links section of the WordPress Administration Panels.
- create a new category called “menuLink”
- insert the menu items as links in this category
Link name is the displayed name on menu. Link description is the title attribute of the link.
To move a link (before or after an other) use the “rating” of the link. This option is available at the end of add/edit link page.
To create drop-down subitems simply add a new link category with the same name of the parent item. And then add links to it.
Note
Function get_bookmarks with category_name argument containg a non-exixting category returns the complete list of bookmarks and not an empty array (or false). So I had to count the total number of bookmarks (on line 13) in order to check if a “sub-category” exixts (line 25).
Un Commento
This is very cool. The only thing I don’t love is that it loses Thematic’s ability to add a
current_page_item class to the page you are currently on, so you can style it differently.
ps- thanks for the english translation!