Nav-links (next/previous post links) to only link to specific categories
-
I have different categories and I’d like my nav-links (next post / previous post) at the bottom of the page to only link within specific categories. For example, when I’m in the category ‘blog’, the next and previous links only link to the next or previous post that falls within the blog category. At the moment, they just link to the next or previous post whichever the category.
The problem is that the nav-links are set in the functions.php file, not in any of the templates, so I’m assuming I have to create a whole load of if statements within function.php to call up each category… or something.
Can anyone help? The relevant code is here:
function twentythirteen_paging_nav() { global $wp_query; // Don't print empty markup if there's only one page. if ( $wp_query->max_num_pages < 2 ) return; ?> <nav class="navigation paging-navigation" role="navigation"> <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1> <div class="nav-links"> <?php if ( get_next_posts_link() ) : ?> <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentythirteen' ) ); ?></div> <?php endif; ?> <?php if ( get_previous_posts_link() ) : ?> <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentythirteen' ) ); ?></div> <?php endif; ?> </div><!-- .nav-links --> </nav><!-- .navigation --> <?php } endif; if ( ! function_exists( 'twentythirteen_post_nav' ) ) : /** * Displays navigation to next/previous post when applicable. * * @since Twenty Thirteen 1.0 * * @return void */ function twentythirteen_post_nav() { global $post; // Don't print empty markup if there's nowhere to navigate. $previous = ( is_attachment() ) ? get_post( $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', 'twentythirteen' ); ?></h1> <div class="nav-links"> <?php previous_post_link( '%link', _x( '<span class="meta-nav">←</span> %title', 'Previous post link', 'twentythirteen' ) ); ?> <?php next_post_link( '%link', _x( '%title <span class="meta-nav">→</span>', 'Next post link', 'twentythirteen' ) ); ?> </div><!-- .nav-links --> </nav><!-- .navigation --> <?php } endif;
Thanks in advance.
- The topic ‘Nav-links (next/previous post links) to only link to specific categories’ is closed to new replies.