Posted By

mesh606 on 03/04/11


Tagged

pages wordpress top level child


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

hkamci


Show Top Level and Child Pages in Wordpress


 / Published in: PHP
 

use this in the sidebar to show a top level page with child pages persistently

  1. <ul><?php $parent_title = get_the_title($post->post_parent);?>
  2. <li><a href="<?php echo get_permalink($post->post_parent) ?>"><?php echo $parent_title;?></a></li></ul>
  3. <?php
  4.  
  5. if ($post->post_parent) {
  6. $ancestors=get_post_ancestors($post->ID);
  7. $root=count($ancestors)-1;
  8. $parent = $ancestors[$root];
  9. } else {
  10. $parent = $post->ID;
  11. }
  12.  
  13. $children = wp_list_pages("title_li=&child_of=". $parent ."&echo=0");
  14.  
  15. if ($children) { ?>
  16. <ul id="subnav">
  17. <?php echo $children; ?>
  18. </ul>
  19. <?php } ?>

Report this snippet  

You need to login to post a comment.