WordPress.org

Ready to get started?Download WordPress

Forums

Wp_nav_menu() to display ONLY submenu pages (3 posts)

  1. chris-babww
    Member
    Posted 2 years ago #

    Hello,

    do you know a way to use the wp_nav_menu() function to display ONLY 2nd level pages?

    Pratically, I have a page with children pages and I would like to display a menu with ONLY that subpages.

    Thank you! :D

    Chris

  2. egado
    Member
    Posted 2 years ago #

    I know that solution... hope that works for you...

    in functions.php

    //display child pages of the current page
    if ( !function_exists('get_children_pages') ) {
    	function get_children_pages() {
    		global $wp_query;
    
    		if ( empty($wp_query->post->post_parent) ) {
    			$parent = $wp_query->post->ID;
    		} else {
    			$parent = $wp_query->post->post_parent;
    		}
    
    		wp_list_pages( 'title_li=&child_of=' . $parent . '&depth=' );
    	}
    }

    in your page.php where the subpages should be shown...
    <?php get_children_pages(); ?>

    Does that work for you?

  3. Adam
    Member
    Posted 1 year ago #

    Hi egado. The function you posted is for wp_list_pages, instead of wp_nav_menu. Do you know of a function that will work for wp_nav_menu?

Topic Closed

This topic has been closed to new replies.

About this Topic