Previous and Next Link
-
So I currently have links which go to previous and next post but I’m trying to build something a bit more complex.
Let’s say I have two parents post and each one of these have at least one or more child posts.
So if I’m in parent post one the next link should take to the next parent post and viceversa(previous parent post), now what I would like to do is if I’m in a child post the link should take to its siblings(next child post and previous child post) not the parent ones.
I currently have this html which in in fact copied from the WordPress codex.
<!-- Previous and Next Post --> <?php if(is_single()) : ?> <div class="btn-group btn-group-justified hidden-sm hidden-xs" role="group" aria-label="..." id="nextpreviouslinks"> <div class="btn-group" role="group"> <button type="button" class="btn btn-default btn-sm"> << <?php previous_post_link( '%link', '%title'); ?></button> </div> <div class="btn-group" role="group"> <button type="button" class="btn btn-default btn-sm"><a href="<?php echo get_permalink( $post->post_parent ); ?>"><?php echo get_the_title( $post->post_parent ); ?></a></button> </div> <div class="btn-group" role="group"> <button type="button" class="btn btn-default btn-sm"> >> <?php next_post_link( '%link', '%title' ); ?></button> </div> </div> <?php endif; ?> <!-- /Previous and Next Post -->
I have tried to look for function online that can do the work but I just don’t find any.
Thanks in advance.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Previous and Next Link’ is closed to new replies.