Support » Fixing WordPress » Add a dynamic menu of parent pages and sub pages…

  • While working on a template to wordpress theme conversion, which used the Dynamic Drive’s Smooth Menu. I needed to dynamic build my menu. Here is what I came up with as far as the menu output:

    <div id="smoothmenu1" class="ddsmoothmenu">
    <li><a href="<?php echo get_option('home'); ?>">Home</a></li>
    $pages = get_pages('parent=0'); 
    foreach ( $pages as $page ) {
         $children = get_pages('child_of='.$page->ID.'&sort_column=post_title');
         $option = '<li><a href="' . get_page_link( $page->ID ) . '">' .$page->post_title.'</a>';
    	if ($children) {
    	     $option .= '<ul>';
                 foreach ( $children as $child ) {
    		$option .= '<li><a href="' . get_page_link( $child->ID ) . '">' .$child->post_title.'</a></li>';
    	     $option .= '</ul>';
    	$option .= '</li>';
            echo $option;
     <br style="clear: left" />

Viewing 1 replies (of 1 total)
  • i would advise using the wordpress dashboard menu’s section.. which allows for nested menus and far more control over what is and isnt displayed..

    add this to your functions.php
    register_nav_menu( 'primary', 'header' );

    you should then see a link under Appearance for your theme that is called ‘Menus’.. you should then be able to create menus of the pages you want for your theme..

    all you would need to do is change the ‘container’ variable when you call the wp_nav_menu() call in your header to ‘ddsmoothmenu’

Viewing 1 replies (of 1 total)
  • The topic ‘Add a dynamic menu of parent pages and sub pages…’ is closed to new replies.