Support » Fixing WordPress » Displaying child page links under the mina nav links

  • Hello, I used some Code that Esmi wrote on a forum post:
    http://wordpress.org/support/topic/only-display-sub-pages-when-top-level-page-is-clicked?replies=11

    the code is:

    <?php
    $my_pages = wp_list_pages('title_li=&depth=1&echo=0');
    if (is_page()) {
    	$this_page = $post->ID;
    	if ($post->post_parent) $this_page= $post->post_parent;
    	$children = get_page_children($this_page, get_pages());
    	if($children) {
    		$my_pages .= "
    <li>\n".'<ul class="subpages">';
    		foreach($children as $child) {
    			$my_pages .= wp_list_pages('title_li=&include='.$child->ID.'&echo=0');
    		}
    		$my_pages .= '</li>
    ';
    	}
    }
    echo $my_pages;
    ?>

    and it works great – the 2nd nav only displays under the first once the parent link is clicked.

    Unfortunately though I cannot order the links as i want to – they only display in alphabetical order. I tried installing the Plugin ‘Simple Page Ordering’ by Jake Goldman – but this seemed to clash with my code the 2nd level deep child links and caused it to not display as i wanted anymore.

    Any suggestions welcome!

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi

    (@esmi)

    Forum Moderator

    Try creating a custom menu instead.

    Hi Esmi – wow thank s for the super-quick response! Ok, will this still allow me to only show child pages’ links when their parent link is clicked?

    Many thanks form a beginner with WordPress!

    esmi

    (@esmi)

    Forum Moderator

    will this still allow me to only show child pages’ links when their parent link is clicked?

    If you add the child pages to the custom menu, yes.

    Hello Esmi,

    I now have my developing site at a live URL – http://www.lucyryderwebprint.co.uk/test

    The code I have in my header.php for the navigation is :
    <div id=”main-nav”>
    <?php wp_nav_menu(); ?>
    </div>

    and I have created a custom menu for the navigation, setting it as the ‘Primary menu’ in Appearance > menus and have 5 child page links under the parent link ‘My work’; all indented to the right to show as its children.

    Currently my child links break the main parent links by sitting as a second line in the navigation.

    I cannot see any options to have the child links only show once the /My work/ link is clicked, I am using twentyeleven with a child theme for the site = could i be missing options that other themes provide perhaps?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Displaying child page links under the mina nav links’ is closed to new replies.