How to use a loop to show parent/child elements in sidebar
-
Sorry, this was hard to word in the title. I current have a site that has a sidebar that shows all the child elements of that section youre in, as well as the title of the parent above all the child elements.
The one problem is that when youre on the parent page, the parents title doesn’t show. This causes it to look inconsistent and kind of jump around
For example: https://developerweek.com/conference/
and then: https://developerweek.com/conference/conference-speakers/For this example, I’d like for “// Conference” to remain at the top of both pages
Here’s the code I’m using:
<ul> <?php if($post->post_parent) { $parent_link = get_permalink($post->post_parent); ?> <a href="<?php echo $parent_link; ?>"><div class="parentz"> // <?php echo empty( $post->post_parent ) ? get_the_title( $post->ID ) : get_the_title( $post->post_parent ); ?> </div></a><?php } ?> <?php if($post->post_parent) $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?> </ul>
Help me esmi or someone!
[Moderator Note: No bumping. If it’s so urgent that you cannot possibly wait ore than 1 hour, consider hiring someone.]
- The topic ‘How to use a loop to show parent/child elements in sidebar’ is closed to new replies.