Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the feedzy-rss-feeds domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /data01/virt126885/domeenid/www.saksadogi.com/codegurus.eu/wp-includes/functions.php on line 6121
Wordpress custom menu display - CodeGurus

WordPress custom menu display

Just a small example of how to build custom menu output in WordPress.

$menu_args		= array('menu' => 'Main menu', 'echo' => 0) ;
$menu_string	= wp_nav_menu($menu_args);
$xml	= new SimpleXMLElement($menu_string);
$out	= false;

foreach ($xml->ul[0] as $li) 
{
	$classes = array('current-page-ancestor', 'current-menu-item', 'current-menu-parent');
	if (strstr($li['class'], 'current-page-ancestor') || 
		strstr($li['class'], 'current-menu-item') || 
		strstr($li['class'], 'current-menu-parent')) 
	{
		$out = $li->ul;      
		$i = 0;
		if (isset($out->li) && !empty($out->li))
		{
			$out['id']		= 'sub_menu';
			$out['class']	= 'clear';
			foreach ($out->li as $li_sub) 
			{      
				if (!strstr($li_sub['class'], 'current-page-ancestor') && 
					!strstr($li_sub['class'], 'current-menu-item') && 
					!strstr($li_sub['class'], 'current-menu-parent')) 
				{
					unset($out->li[$i]->ul);
				}
				$i++;
			}
		}
		break;;
	}
}
if (!empty($out)) {
	 echo $out->asXML(); 
}

Posted

in

,

by

Comments

Leave a Reply