• Working with a Twentyfourteen child theme and need my next-post/previous-post navigation to stay in the post’s category but none of the fixes I saw online as well as on wordpress codex worked for me in this theme. I understand I need to modify the code in the inc/template-tags.php, but whatever I tried was ignored. I’d appreciate any help.

    Here is the code:

    if ( ! function_exists( 'twentyfourteen_post_nav' ) ) :
    /**
     * Display navigation to next/previous post when applicable.
     *
     * @since Twenty Fourteen 1.0
     */
    function twentyfourteen_post_nav() {
    	// Don't print empty markup if there's nowhere to navigate.
    	$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
    	$next     = get_adjacent_post( false, '', false );
    
    	if ( ! $next && ! $previous ) {
    		return;
    	}
    
    	?>
    	<nav class="navigation post-navigation" role="navigation">
    		<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
    		<div class="nav-links">
    			<?php
    			if ( is_attachment() ) :
    				previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
    			else :
    				previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
    				next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
    			endif;
    			?>
    		</div><!-- .nav-links -->
    	</nav><!-- .navigation -->
    	<?php
    }
    endif;
  • The topic ‘restricting post nav to category’ is closed to new replies.