This simple plugin was written to add classes to first, last, parent, even and odd elements of wp_page_menu and wp_nav_menu to support recognizing it in older browsers without :first-child, :last-child and :nth-child supporting.
Plugin adds the following classes to menu <li> tags:
- “first-menu-item” to every first child of <ul> or <menu> tag,
- “last-menu-item” to every last child of <ul> or <menu> tag,
- “parent-menu-item” to every child of <ul> or <menu> tag that has another <ul> or <menu> tag inside (a parent to another menu level),
- “odd-menu-item” to every odd child of <ul> or <menu> tag, including first and/or last child,
“even-menu-item” to every even child of <ul> or <menu> tag, including first and/or last child.
Above classes are added separately to each menu level. Plugin use SimpleXML extension and requires PHP 5 or higher. Menu should have valid XHTML code.
- Upload “majpage-menu-class-extender.php” to the “/wp-content/plugins/” directory.
- Activate the plugin through the “Plugins” menu in WordPress.
- That’s all – plugin is fully operational and adds specified classes in every wp_page_menu and wp_nav_menu element with menu defined in “Menus” tab.
以下人員參與了開源軟體〈MAJpage Menu Class Extender〉的開發相關工作。參與者
- Fix missed variable declarations.
- Replace deprecated function.
- Plugin functions changed into MAJpageMCE class static methods.
- wp_page_menu container support added thanks to Dinesh Kesarwani’s notice.
- Cause of the strict standards warning corrected thanks to flynsarmy’s notice.
- HTML5 <menu> tag support added thanks to Tomas Kapler’s notice.
- wp_nav_menu container tag support included.
- Bug fixed with correct working in case of wp_nav_menu container absence.
- “parent-menu-item” class added.
- Bug fixed with HTML special chars existence.
- Improved menu list searching inside a container.
- First version of plugin.