Next/Previous on Pages
-
I got help with a similar issue here a while back, but here we go for round two.
I’m using the following code in content.php to display navigation on the bottom of my posts. It’s gorgeous and works beautifully. On posts. Now I’m trying to get it to work on pages, and the best I can do are two ugly little links that show up in very weird places on archive pages.
<div class="post-meta-bottom"> <?php $prev_post = get_previous_post(true); $next_post = get_next_post(true); if ( $prev_post || $next_post ) : ?> <nav class="post-nav group"> <?php if ( $prev_post ) : ?> <a class="post-nav-older" href="<?php the_permalink( $prev_post->ID ); ?>"> <h5><?php _e( 'Previous post', 'hemingway' ); ?></h5> <?php echo get_the_title( $prev_post->ID ); ?> </a> <?php endif; ?> <?php if ( $next_post ) : ?> <a class="post-nav-newer" href="<?php the_permalink( $next_post->ID ); ?>"> <h5><?php _e( 'Next post', 'hemingway' ); ?></h5> <?php echo get_the_title( $next_post->ID ); ?> </a> <?php endif; ?> </nav><!-- .post-nav --> <?php endif; ?> </div><!-- .post-meta-bottom -->
The site this is on is a fiction archive, so allowing readers to just carry on to the next chapter is pretty important. So far the only thing I’ve got to work that does the same job is
<?php previous_post_link( '« %link', '%title', true ); ?> || <?php next_post_link( '%link »', '%title', true ); ?>
And it works… fine. I just hate it. I’ll use it if I have to, but I feel like I’m either missing something terribly obvious, or trying to get WordPress to do something it doesn’t want to to.
I’d like to avoid using plugins if possible, because I’m already relying on too many, and would rather hardcode as much as possible for future-proofing.
The page I’ve linked to is a fairly typical example of how a mid-chapter page is currently behaving (scroll to the bottom for the uggo footer). What I want it to look like can be seen on this post.
Thanks!
- The topic ‘Next/Previous on Pages’ is closed to new replies.