Extra output in custom wp_list_pages
-
Hi —
In a menu, I want to display only the current page + ancestors + child.
I’m using this:
<?php //if the post has a parent if($post->post_parent){ //collect ancestor pages $relations = get_post_ancestors($post->ID); //get child pages $result = $wpdb->get_results( "SELECT ID FROM wp_posts WHERE post_parent = $post->ID AND post_type='page'" ); if ($result){ foreach($result as $pageID){ array_push($relations, $pageID->ID); } } //add current post to pages array_push($relations, $post->ID); //get comma delimited list of children and parents and self $relations_string = implode(",",$relations); //use include to list only the collected pages. $sidelinks = wp_list_pages("title_li=&echo=0&include=".$relations_string); }else{ // display only main level and children $sidelinks = wp_list_pages("title_li=&echo=0&depth=1&child_of=".$post->ID); } if ($sidelinks) { ?> <h2><?php the_title() ;?></h2> <ul> <?php echo $sidelinks; ?> </ul> <?php } ?>
The problem is that I get the current page title (“Test menu” here, parent page is “TEST”) printed within <h2> tags (and without closing /ul tag) breaking the menu as seen here:
https://img718.imageshack.us/img718/5405/image39.pngHTML source code output :
<li><a href="#">Pages</a> <ul> <h2>Test menu</h2> <ul> <li class="page_item page-item-116 current_page_ancestor current_page_parent"><a href="https://www.mysite.com/films/test-3/" title="TEST">TEST</a> <ul> <li class="page_item page-item-122 current_page_item"><a href="https://www.mysite.com/films/test-3/test-menu/" title="Test menu">Test menu</a></li> </ul> </li> </ul> </ul> </li>
I’m using “Fullscreen theme” on 2.9.2
Where should I look up to fix this?
TIA.
- The topic ‘Extra output in custom wp_list_pages’ is closed to new replies.