Skip to content

Instantly share code, notes, and snippets.

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 gabrielizalo/56b028c8930ea796cec79829d3a0a657 to your computer and use it in GitHub Desktop.
Save gabrielizalo/56b028c8930ea796cec79829d3a0a657 to your computer and use it in GitHub Desktop.
Wordpress - Easily Navigate Within a Section of Pages
// Taken from: https://speckyboy.com/wordpress-snippets-secondary-navigation/
/*
This code makes for a great secondary navigation menu that could be used, for example, within a sidebar. It automatically displays the pages within the current section you’re browsing.
As an example, let’s say your site has an About Us page, with subpages for History, Mission Statement and Staff. Users will be able to more easily navigate between the various pages within this section as a bulleted list of links.
*/
<?php
if ( $post->post_parent ) {
$children = wp_list_pages( array(
'title_li' => '',
'child_of' => $post->post_parent,
'echo' => 0
) );
} else {
$children = wp_list_pages( array(
'title_li' => '',
'child_of' => $post->ID,
'echo' => 0
) );
}
if ( $children ) : ?>
<ul>
<?php echo $children; ?>
</ul>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment