• How can I show the child pages in the menu?

    Right now, I have a plugin that displays the children of the parent page you are viewing in the sidebar, while the parents are in the header menu (as default).

    How can I switch these two positions? So that the parents are in the sidebar (easy, just put “pages” as a widget) and put the children of the page you are viewing in the header menu?

    Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Twenty Ten is integrated with the WP Menus manager. Have you tried playing around with that? No plugin required (and comes with a widget to throw in a sidebar).

    Dashboard -> Appearance -> Menus

    Thread Starter Jam

    (@pimaniii)

    I can easily create custom menus, but how can I display the child pages of ONLY the page you are viewing, and have them change when you look at a different parent page?

    You can still use wp_menu() and create a function to return the child pages of the top level item 'fallback_cb'=>'digimag_child_categories' and add a none location.

    In a theme I am working, I have a main menu and two category menus, the top level categories and a the child level menus both show on my theme.

    The way this works is I have a function ‘digimag_child_categories’ in functions.php to find the top level category and all the levels below that.

    Here is the code you would need to change this for pages.
    https://pastebin.com/97Kqt8JU

    I call this menu like this:

    <?php if ( is_category() ) : ?>
    		<div id="access" role="navigation">
    			<div class="menu-header">
    				<ul class="menu">
    					<?php wp_nav_menu( array( 'container_class' => '','theme_location' => 'none','fallback_cb'=>'digimag_child_categories') ); ?>
    				<ul>
    			</div>
    		</div>
    	<?php endif; ?>

    There is no cat-ancestor class so the code is bloated as I had to add it to cater for many levels, the nice thing is that the menu only shows if there are children see the category years no children.

    HTH

    David

    Thread Starter Jam

    (@pimaniii)

    Whoa! That is almost exactly what I am looking for, thank you! I will give it a try and come back if I have questions, thanks!

    Thread Starter Jam

    (@pimaniii)

    Ok,

    1. How can I assign Pages to categories (as either parent or child, or does it automatically do this?)

    Thanks!

    Thread Starter Jam

    (@pimaniii)

    Check out my previous post…

    I uploaded the fuctions.php code (but changed the name of digimag) but I think I am missing something here…

    I posted the display php but nothings showing up…

    What did you name the menu (of parents?), digimag?

    1. How can I assign Pages to categories (as either parent or child, or does it automatically do this?)

    The code is just an example, I wrote:
    Here is the code you would need to change this for pages.

    This is UNTESTED code, so test on a local install!

    if ( ! function_exists( 'digimag_child_pages' ) ) :
    function digimag_child_pages() {
    	if ( is_page() ) {
    		global $post;
    		$id=$post->post_parent;
    		//No Parent Return Nothing
    		if(!$id) return "";
    		$list_args = 'style=list&child_of='.$id.'&depth=0&hierarchical=true&title_li=0&echo=0';
    		$pagelist = wp_list_pages($list_args);
    		$menu = str_replace( array( "\r", "\n", "\t" ), '', $pagelist );
    		echo $menu;
    	}
    	return  "";
    }
    endif;

    The call it

    <?php if ( is_page() ) : ?>
    	<div id="access" role="navigation">
    		<div class="menu-header">
    			<ul class="menu">
    				<?php wp_nav_menu( array( 'container_class' => '','theme_location' => 'none','fallback_cb'=>'digimag_child_pages') ); ?>
    			<ul>
    		</div>
    	</div>
    <?php endif; ?>

    NOTE This code is for the Twenty Ten theme classes, and only works at two levels parent and child, if you had
    Page 1
    -Page 2
    –Page 3
    -Page 4
    -Page 5
    -Page 6
    The visitor selected ‘Page 3’ the menu would only show ‘Page 3’ as Page 2 is the Parent and ‘Page 1’ is the Ancestor up another level in the tree.

    If you are going to use three levels and you need to find the top level, then check this code

    HTH

    David

    Thread Starter Jam

    (@pimaniii)

    Thanks for responding!

    By “pages” do you mean in functions.php where page menu is?

    I am working in 2010, so it would be:

    function twentyten_page_menu_args( $args ) {
    	$args['show_home'] = true;
    	return $args;
    }
    add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );

    Do I add that code beneath (or replace) this? Sorry, I am new to menu management with WP.

    Or, does this code go in page.php? If so, where? After header?

    And 2 levels is perfect, thanks!

    You do not touch that code at all this code is a new fall back function.

    The Function is complete a standalone function and goes in functions.php, so do not add this unless you know what you are doing, and have a local install for testing, as an error will lock you out of the admin area, and I have not tested this code!

    The second menu part goes where the existing menu section is in twenty ten header.php.

    HTH

    David

    Thread Starter Jam

    (@pimaniii)

    Ok, thank you for the warning. I have successfully placed your previous code code in my functions.php, and placed the display code in the right place. But nothing shows up.

    I’ll try that untested code.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Twenty Ten, how to show child page in menu?’ is closed to new replies.