Skip to content

Instantly share code, notes, and snippets.

@kirasiris
Last active November 3, 2017 09:45
Show Gist options
  • Save kirasiris/464169fbfa7f79e4c95e4c601a4dea92 to your computer and use it in GitHub Desktop.
Save kirasiris/464169fbfa7f79e4c95e4c601a4dea92 to your computer and use it in GitHub Desktop.
<?php
/// Esto va en su archivo functions.php
function get_top_parent(){
global $post;
if($post->post_parent){
$ancestors = get_post_ancestors($post->ID);
return $ancestors[0];
}
return $post->ID;
}
function page_is_parent(){
global $post;
$pages = get_pages('child_of='.$post->ID);
return count($pages);
}
?>
<!-- Esto lo deberan incluir en su archivo page.php -->
<?php if(page_is_parent() || $post->post_parent > 0) : ?>
<div class="pagination pull-right">
<li>
<span class="parent-link"><a href="<?php echo get_the_permalink(get_top_parent()); ?>"><?php echo get_the_title(get_top_parent()); ?></a></span>
<?php
$args = array(
'child_of' => get_top_parent(),
'title_li' => ''
);
?>
<?php wp_list_pages($args); ?>
</li>
</div>
<div class="clearfix"></div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment