I'm trying to convert my static nav menu to WP dynamic nav.
This is what I've got:
<nav>
<ul id="menu">
<?php
$pages = array( 'index.php' => 'Home', 'services.php' => 'Services', 'sitemap.php' => 'Calculators', 'about.php' => 'About'
, 'contact.php' => 'Contact' );
$query = $_SERVER['PHP_SELF'];
$path = pathinfo( $query );
$selected = $path['basename'];
foreach( $pages as $url => $title ) {
$li = '<li ';
if( $url === 'index.php' ) {
$li .= 'class="alpha"';
} else if ( $url === 'contact.php' ){
$li .= 'class="omega"';
}
if( $selected == $url ) {
$li .= 'id="menu_active"';
}
$li .= '><a href="' . $url . '"><span><span>' . $title . '</span></span></a></li>';
echo $li;
}
?>
</ul>
</nav>
But I've read that I need to use this?
<?php wp_nav_menu( array(
'theme_location' => 'primary',
'container' => false,
'menu_class' => 'menu'
) ); ?>
I really don't get it nor how to implement this? Any ideas? I really am stuck with this so help is much needed and appreciated. Thanks.
Now generate new menu from
Appearance -> Menus
and add this new menu as top-menu.Try this. This will use the default menu you have set up in Wordpress. You can specify the menu name of a non default menu also. This will wrap the menu items in a
<ul></ul>
tag.You can try this:
And also write the following code in functions.php:
Try using firebug, you will find some classes in li tag i.e.
current-menu-item
,sub-menu
inli ul li
,current-menu-parent
in parentli
once you clicked the child item ,current-menu-ancestor
in child li etc. Transfer your css properties into these classes.Moreover, if you want to include specific class for particular li, so please go to
Appearance>menus
, you will find an option at right-top corner i.e. "Screen Options", click there. Panel will be expanded then check the option "CSS Classes" under "Show advanced menu properties". Now you will find an input field "CSS Classes (optional)" once you expand menu from right panel. Just put there your specific class for specific li. panel.I hope this is everything to work with menu. :)