Last active
August 29, 2015 14:07
-
-
Save mattradford/713f99f2b5ea06c178dc to your computer and use it in GitHub Desktop.
Get siblings of post. Remove . '&exclude=' . $post->ID to include current post.
This file contains 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 | |
// global $post; //not necessary if used in the loop | |
$parent_id = $post->post_parent; | |
if( $parent_id ) : | |
$siblings = get_pages( 'child_of=' . $parent_id . '&parent=' . $parent_id . '&exclude=' . $post->ID); | |
if( $siblings ) foreach( $siblings as $sibling ) : | |
//start of whatever you need to output// | |
echo $sibling->post_title; | |
echo get_the_post_thumbnail($sibling->ID,'medium'); | |
//end of whatever you need to output// | |
endforeach; | |
endif; //ends if( $parent ) // | |
?> | |
// Includes current post and active class | |
<nav class="subnav"> | |
<?php | |
$parent_id = $post->post_parent; | |
if( $parent_id ) : | |
$siblings = get_pages( 'child_of=' . $parent_id . '&parent=' . $parent_id); | |
if( $siblings ) : | |
echo "<ul>"; | |
foreach( $siblings as $sibling ) : | |
if($sibling->ID == $post->ID) : | |
echo '<li class="active"><a>'.$sibling->post_title.'</a></li>'; | |
else : | |
echo '<li><a>'.$sibling->post_title.'</a></li>'; | |
endif; | |
endforeach; | |
echo "</ul>"; | |
endif; //ends if( $parent ) // | |
endif; //ends if( $parent ) // | |
?> | |
</nav> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment