• Resolved mvanboordt

    (@mvanboordt)


    Hi,

    I am currently creating a custom theme.
    One page consists subpages of a top-menu.
    If the menu get’s clicked the page shows a list of the submenu’s that are beneath the page.
    The submenu on the page works great, however when I look at the navigation I see that there is a subpage created under the main menu but this is nog what I want.

    In short:
    The main menu is not allowed to have submenu’s showing.
    The page only display’s the submenu.

    This is what I use for the mainmenu:

    <?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'menu_class' => 'nav', 'theme_location' => 'primary-menu' ) ); ?>

    And this is what I use to get my submenu on a page:

    <?php
    $mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );
    
    foreach( $mypages as $page ) {
    	$content = $page->post_content;
    	if ( ! $content ) // Check for empty page
    		continue;
    
    	$content = apply_filters( 'the_content', $content );
    ?>
    	<h3><?php echo $page->post_title; ?></h3>
    	<div class="entry"><a href="<?php echo get_page_link( $page->ID ); ?>">READ MORE »</a></div>
    <?php
    }
    ?>

    Can somebody tell me what I need to change to get the submenu out of the main menu and only on the page.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Add 'depth' => 1 to your mainmenu wp_nav_menu() arguments array, if you don’t want the subpage to appear in the main menu.

    Thread Starter mvanboordt

    (@mvanboordt)

    Very nice.

    Thank you that worked like a charm.

    M

    Thread Starter mvanboordt

    (@mvanboordt)

    @chip Bennett

    I was wondering. In the current script you see above is is possible to also show the featured image?

    Thnx in advance.

    M.

    Thread Starter mvanboordt

    (@mvanboordt)

    Aaahhhhwwww Yeeeaaaahhhh

    Figured it out and changed the code.

    FYI:

    <?php
    				$child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent = ".$post->ID."    AND post_type = 'page' ORDER BY menu_order", 'OBJECT');    ?>
    					<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
    						<div class="container_page">
    							<div class="featured_image">
    								<?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?>
    							</div>
    							<div class="featured_content">
    								<h3><?php echo $page->post_title; ?></h3>
    								<?php echo $pageChild->post_title; ?>
    								<a href="<?php echo  get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>">READ MORE »</a>
    							</div>
    						</div>
    					<?php endforeach; endif;
    			?>

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

The topic ‘Subpage not in Menu’ is closed to new replies.