Note that there are some explanatory texts on larger screens.

plurals
  1. POwp_list_pages, hide parent with no ancestor and show children to chosen post
    text
    copied!<p>I'am trying to create a menu using wp_list_pages and I want the end result to look like this:</p> <pre><code>parent ( no ancestor ) &lt;-- This one should be hidden - Children "Some Title"( clicked ) - Children1 to "Some Title" - Children2 to "Some Title" - Children "Some other title" ( When clicking on this, children to "Somte Title" will hide and children to "Some other title" show ) </code></pre> <p>I am using the following code, and I cant figure out how to modify it to give me the result I want.</p> <pre><code>&lt;?php //if the post has a parent if($post-&gt;post_parent){ //collect ancestor pages $relations = get_post_ancestors($post-&gt;ID); //get child pages $result = $wpdb-&gt;get_results( "SELECT ID FROM wp_posts WHERE post_parent = $post-&gt;ID AND post_type='page'" ); if ($result){ foreach($result as $pageID){ array_push($relations, $pageID-&gt;ID); } } //add current post to pages array_push($relations, $post-&gt;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=&amp;echo=0&amp;include=".$relations_string); }else{ // display only main level and children $sidelinks = wp_list_pages("title_li=&amp;echo=0&amp;depth=1&amp;child_of=".$post-&gt;ID); } if ($sidelinks) { ?&gt; &lt;?php echo the_title(); ?&gt; &lt;ul&gt; &lt;?php //links in &lt;li&gt; tags echo $sidelinks; ?&gt; &lt;/ul&gt; &lt;?php } ?&gt; </code></pre> <p>The example above gives me a layout looking like this and it shows the parent with no ancestor and not the sibling to the clicked Children:</p> <pre><code>parent ( no ancestor ) - Children "Some Title"( clicked ) - Children1 to "Some Title" - Children2 to "Some Title" </code></pre> <p>Appreciate any help! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload