Skip to content

Instantly share code, notes, and snippets.

@sta1r
Created April 4, 2014 11:13
Show Gist options
  • Select an option

  • Save sta1r/9972462 to your computer and use it in GitHub Desktop.

Select an option

Save sta1r/9972462 to your computer and use it in GitHub Desktop.
Wordpress page menu that shows all top-level pages, and child pages when EITHER the current page has children, OR the current child page has siblings.
<?php
$all_pages = get_pages();
foreach ($all_pages as $page) {
if (!$page->post_parent) {
$incl .= $page->ID . ",";
} elseif ($page->post_parent == $post->ID ||
$page->post_parent == $post->post_parent) {
$incl .= $page->ID . ",";
} else {
continue;
}
}
?>
<ul>
<?php
wp_list_pages(array(
"include" => $incl,
"link_before" => "",
"title_li" => "",
"sort_column" => "menu_order"
));
?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment