Last active
April 24, 2019 03:13
-
-
Save gstricklind/27301cb225f54d57ff4d to your computer and use it in GitHub Desktop.
WordPress: Dynamically shows first level child pages of a parent page without using a widget or menu.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
global $post; | |
if(!$post->post_parent){ | |
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); | |
} else{ | |
if($post->ancestors) { | |
//$ancestors = end($post->ancestors); | |
$ancestors = end( get_post_ancestors($post) ); | |
$children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0"); | |
} | |
} | |
if ($children) { | |
?> | |
<aside id="child-pages" class="widget widget_child_pages"> | |
<ul> | |
<?php echo $children; ?> | |
</ul> | |
</aside> | |
<?php } ?> | |
<? //Placement: I usually place this code above the normal call for the sidebar ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment