WordPress Menus on the top

Once you download the wordpress’ default theme, the navigation code that appears by default uses wp_nav_menu and looks like

wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) );

The issue with wp_nav_menu is that along with the pages, a default home page titled ‘Home’ too appears alongside just before the list of pages which is not desirable. If one goes along, he will have all the menu items fetched from the ‘pages’ except the ‘Home’ page that will be a post by default.

The way out is to use wp_list_pages and the code that I used looks something like

wp_list_pages('sort_column=menu_order&title_li=<h2>' . __('Poetry') . '</h2>');

Also for the children (the sub pages of the parent menu or the sub menu), the code to be used so as to be able to fetch the sub menu items is

$children=wp_list_pages("title_li=&child_of=".$post->ID);
if($children){
echo $children;
}

The style sheet can be changed accordingly.
An interesting link with reference to this is here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: