Return to Snippet

Revision: 30383
at August 13, 2010 01:40 by simonbouchard


Updated Code
<?php
	global $post; $thispage = $post->ID; // grabs the current post id from global and then assigns it to $thispage
	$subpages = get_pages("child_of=".$thispage."&sort_column=menu_order"); // gets a list of pages that are sub pages of $thispage and assigns it to $pagekids
?>

<?php if ($subpages) { // if there are any values stored in $pagekids, meaning there are sub-pages of the current page ?>

	<ul class="links">
		<?php wp_list_pages("depth=1&title_li=&sort_column=menu_order&child_of=".$thispage); // display ONLY the sub pages of the current page ?>
	</ul>

<?php } else { // $pagekids is empty ?>

	<ul class="links">
		<?php wp_list_pages('depth=1&title_li=&child_of='.$post->post_parent.'&sort_column=menu_order'); // display the sub-pages of the current parent page ?>
	</ul>

<?php } ?>

Revision: 30382
at August 13, 2010 01:39 by simonbouchard


Initial Code
<?php
	global $post; $thispage = $post->ID; // grabs the current post id from global and then assigns it to $thispage
	$subpages = get_pages("child_of=".$thispage."&sort_column=menu_order"); // gets a list of pages that are sub pages of $thispage and assigns it to $pagekids
?>

<?php if ($subpages) { // if there are any values stored in $pagekids, meaning there are sub-pages of the current page ?>

  <ul class="links">
    <?php wp_list_pages("depth=1&title_li=&sort_column=menu_order&child_of=".$thispage); // display ONLY the sub pages of the current page ?>
  </ul>

<?php } else { // $pagekids is empty ?>

  <ul class="links">
    <?php wp_list_pages('depth=1&title_li=&child_of='.$post->post_parent.'&sort_column=menu_order'); // display the sub-pages of the current parent page ?>
  </ul>

<?php } ?>

Initial URL


Initial Description
This code will list all children pages from a parent page. This method is useful when you don\\\'t want to list all parent pages when you are on a parent page that have no children pages.

Initial Title
WordPress: Custom Sub Navigation

Initial Tags
wordpress

Initial Language
PHP