Parent children in sidebar
-
Hopefully a very simple tweak required here:
The following sidebar script is doing ALMOST exactly what I want:
- On top-level pages with no children, it displays nothing. This is key.
- On top-level pages with children AND on its child pages, it lists the parent page name and links to the other children under that parent.
The change I would like is this: instead of simply listing the parent page name, I would like a live link to that parent. This is probably remedial but it’s baffled me.
<?php /* if the current pages has a parent, i.e. we are on a subpage */ if ( $post->post_parent) { $parent_title = get_the_title($post->post_parent); $children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0"); // list the parent page $children = wp_list_pages("depth=1&title_li=&child_of=".$post->post_parent."&echo=0"); // append the list of children pages to the same } // $children variable /* else if the current page does not have a parent, i.e. this is a top level page */ else { $parent_title = get_the_title($post->ID); $children = wp_list_pages("title_li=&include=".$post->ID."&echo=0"); $children = wp_list_pages("depth=1&title_li=&child_of=".$post->ID."&echo=0"); // form a list of the children of the current page } /* if we ended up with any pages from the queries above */ //if ($parent_title) { // echo $parent_title; //} if ($children) { echo "<div style='width: 220px; background: #e8e0cb; padding: 25px; height: 100%;'>"; echo $parent_title; echo "<ul style='list-style: none; padding-left: 20px;'>"; echo $children; /*print list of pages*/ echo "</ul>"; echo "</div>"; } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Parent children in sidebar’ is closed to new replies.