How get current menu childrens from main menu?
-
Hello!
I have a problem. I can’t find solution for my target.
I need get current menu children list.Example:
-Parent 1
–Child A
–Child B
–Child C
-Parent 2
–Child B
–Child CAll children’s parent is Parent 1 (but not Parent 2).
But in navigation I have grouped the products.
When I go to “Parent 1” or “Parent 2” page, then in the page generated the list of products (children’s pages).First solution I write where get the page children:
<?php $mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc', 'post_status' => 'publish' ) ); foreach( $mypages as $page ) { $content = apply_filters( 'the_content', $page->post_content); if ( ! $content ){ // Check for empty page continue; } ?> <figure class="img_with_caption category_caption"> <?php $img_src = get_post_image(); if(!empty($img_src)){ ?> <a href="<?php echo get_page_link( $page->ID ); ?>"> <img class="alignleft category_img" src="<?php echo $img_src; ?>" alt="<?php echo get_page_link( $page->ID ); ?>" /> </a> <?php } ?> <figcaption> <h3><?php echo $page->post_title; ?></h3> <p><?php $str1 = substr($content, strpos($content, '</figure>')+9); $content_fragment = substr($str1, 0, strpos($str1, '.')+1); echo $content_fragment; ?></p> <p><a href="<?php echo get_page_link( $page->ID ); ?>"> <?php $lang = qtranxf_getLanguage(); $caption = get_content_data(); echo $caption[$lang]["read-more"]; ?></a></p> </figcaption> </figure> <?php } ?>And its working fine, but I can’t grouped the products.
I need get all this via menu navigation, but not via page relationship.I all day searching how write the solution, bet can’t find.
Only this code I get:$current_terms = get_queried_object(); $locations = get_nav_menu_locations(); $menu = wp_get_nav_menu_object( $locations[ 'health' ] ); $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'post_parent' => $current_terms->ID ) ); if( !empty( $menu_items ) ) { echo '<ul>'; foreach( $menu_items as $menu_item ) { echo '<li><a href="' . $menu_item->url . '">' . $menu_item->title . '</a></li>'; } echo '</ul>'; }But
wp_get_nav_menu_items( $menu->term_id, array( 'post_parent' => $current_terms->ID ) );
this function working only in “Parent 1” page and show relationship children, AND dublicate, because the same children’s is in “Parent 2”.But on Parent 2 page not showing.
Please help me some one.
Thank you.
The topic ‘How get current menu childrens from main menu?’ is closed to new replies.