Wordpress - Show link to the next and previos brother of the current page, and a link to the page parent


/ Published in: PHP
Save to your folder(s)

Must be placed after the_post()


Copy this code and paste it in your HTML
  1. <?
  2. if (!empty($post->post_parent)) {
  3. $pagelist = get_pages("child_of=".$post->post_parent."&parent=".$post->post_parent."&sort_column=menu_order&sort_order=asc");
  4. $pagini = array();
  5. foreach ($pagelist as $pagina) {
  6. $pagini[] += $pagina->ID;
  7.  
  8. }
  9. }
  10.  
  11. $current = array_search($post->ID, $pagini);
  12. $prevID = $pagini[$current-1];
  13. $nextID = $pagini[$current+1];
  14. ?>
  15. <div class="navigation">
  16. <?php if (!empty($post->post_parent)) { ?>
  17. <div style="clear:both;"><a href="<?php echo get_permalink($post->post_parent); ?>"
  18. title="<?php echo get_the_title($post->post_parent); ?>"> <?php echo get_the_title($post->post_parent); ?></a></div>
  19. <?php } if (!empty($prevID)) { ?>
  20. <div class="alignleft">
  21. <a href="<?php echo get_permalink($prevID); ?>"
  22. title="<?php echo get_the_title($prevID); ?>">&laquo; <?php echo get_the_title($prevID); ?></a>
  23. </div>
  24.  
  25. <?php }
  26. if (!empty($nextID)) { ?>
  27. <div class="alignright">
  28. <a href="<?php echo get_permalink($nextID); ?>"
  29. title="<?php echo get_the_title($nextID); ?>"><?php echo get_the_title($nextID); ?> &raquo;</a>
  30. </div>
  31. <?php } ?>
  32. </div>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.