Skip to content

Instantly share code, notes, and snippets.

@kreamweb
Last active December 12, 2015 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kreamweb/4745058 to your computer and use it in GitHub Desktop.
Save kreamweb/4745058 to your computer and use it in GitHub Desktop.
[Wordpress] Display a list of pages from with all subchilds. A complete dynamic menu
<?php
$a=get_post_ancestors($post->ID,'page');
if(empty($a)){
//I'm in the root page
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
$title=$post->post_title;
$id=$post->ID;
}else{
//I'm in a sub page
$last=array_pop($a);
$children = wp_list_pages("title_li=&child_of=".$last."&echo=0");
$post_parent=get_post($last);
$title=$post_parent->post_title;
$id=$post_parent->ID;
}
if ($children) { ?>
<div class="title-menu"><a href="<?php echo get_permalink($id) ?>"><?php echo $title ?></a></div>
<div id="side-menu">
<ul><?php echo $children; ?></ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment