Skip to content

Instantly share code, notes, and snippets.

@colinfwren
Created June 26, 2011 18:29
Show Gist options
  • Save colinfwren/1047831 to your computer and use it in GitHub Desktop.
Save colinfwren/1047831 to your computer and use it in GitHub Desktop.
Code to add all parent pages
<?php
if(!$post->post_parent){
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1");
}else{
if($post->ancestors){
$ancestors = array_reverse($post->ancestors, true);
foreach($ancestors as $ancestor){
$ancestor = wp_list_pages("title_li=&child_of=".$ancestor."&echo=0&depth=1");
echo "<ul>";
echo $ancestor;
echo "</ul>";
}
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1");
}
}
if ($children) {
echo "<ul>";
echo $children;
echo "</ul>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment