Last active
August 29, 2015 14:02
-
-
Save blainerobison/f17b4a0d8f4ce1940aac to your computer and use it in GitHub Desktop.
wp: Display immediate children or siblings as a menu. [WordPress]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get related menu | |
* | |
* Displays immediate children or siblings | |
* | |
* @param boolean $echo echo or return result | |
* @return str $r | |
*/ | |
function prefix_related_menu( $echo = true ) { | |
global $post; | |
$r = ''; | |
// bail if we don't have any ids to work with | |
if( is_null( $post ) ) | |
return $r; | |
// get children | |
$pages = wp_list_pages( 'title_li=&child_of=' . $post->ID . '&echo=0' ); | |
// get siblings | |
if( ! $pages && $post->post_parent ) { | |
$pages = wp_list_pages( 'title_li=&child_of=' . $post->post_parent . '&depth=1&echo=0' ); | |
} | |
// output menu | |
if( $pages ) { | |
$r .= '<div class="widget">' . "\n"; | |
$r .= ' <h3 class="widget__heading">Related</h3>' . "\n"; | |
$r .= ' <ul class="menu related-menu">' . "\n"; | |
$r .= ' ' . $pages . "\n"; | |
$r .= ' </ul>' . "\n"; | |
$r .= '</div>' . "\n"; | |
} | |
if( $echo ) : | |
echo $r; | |
else : | |
return $r; | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment