Tagged: category
- This topic has 5 replies, 2 voices, and was last updated 10 years, 3 months ago by Sakin.
-
AuthorPosts
-
July 23, 2014 at 7:03 am #41298JoshParticipant
Hello,
I am trying to limit the “previous” and “next post” links after the content on my single posts pages to the same taxonomy as the post itself, i.e., preferably by category. I have found some helpful WP articles:
http://codex.wordpress.org/Function_Reference/next_post_link
http://codex.wordpress.org/Function_Reference/previous_post_link
but I can’t find the “in_same_term” parameter mentioned in those articles in Catch Everest Pro’s single.php file or any where else.
Thanks for a great theme. I am very close to going live. Any help would be greatly appreciated!
July 23, 2014 at 11:30 am #41310SakinKeymaster@jmott310: Sorry I don’t understand your question what do you mean by limit Previous & Next Post Links to Articles in Same Category. In single post it is controlled through
catcheverest_content_nav( 'nav-below' );
function called insinple.php
file and you will find that function intemplate-tags.php
file.Note: please don’t edit any core theme files inside
catch-everest-pro
theme directly. As these files will be reverted back when you update the theme. So, if you want to edit these files and functions then you need to build Child Theme and do your edits.July 23, 2014 at 4:45 pm #41323JoshParticipantSorry, I wasn’t clear. I have my blog divided into categories. When someone views a single post the nav links you mention show links to the “previous” and “next” posts regardless of the category each post is in. So, for example, if I am viewing a post in category “B” the “previous” and “next” post links may point to articles in categories “A” and “C” depending on when each particular post was published. However, I am trying to force those nav links to only point to the “previous” and “next” posts that have the same taxonomy (i.e., category) as the post being viewed. So if I am viewing a single post in category “B” I would like the “previous” and “next” post links to only point to the “previous” and “next” posts that are also in category “B” and ignore the posts in categories “A” and “C.” The links I posted above show how to do this with a php code/argument that is different from the code found in the single.php for this theme. Sorry I didn’t post a link to my site. It is not quite live yet. If you send me an email I will set up an admin account for you to take a look at what I am talking about. Thanks for the great support and a great theme!
July 23, 2014 at 10:50 pm #41338SakinKeymaster@jmott310: I gave you the clear instruction. So, you can build child theme and then copy
catcheverest_content_nav
function fromtemplate-tags.php
file to your child theme newfunctions.php
file.In this function, you will see the following code, which you can edit as per your need.
<?php if ( is_single() ) : // navigation links for single posts ?> <?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'catcheverest' ) . '</span> %title' ); ?> <?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'catcheverest' ) . '</span>' ); ?>
July 24, 2014 at 7:33 am #41360JoshParticipantThanks Sakin! Great support!!! Using your advice and the parameters in the WP Codex found in the links in my earlier post I resolved the issue by adding the following code to the functions.php file in my child theme:
if ( ! function_exists( 'catcheverest_content_nav' ) ) : /** * Display navigation to next/previous pages when applicable * * @since Catch Everest 1.0 */ function catcheverest_content_nav( $nav_id ) { global $wp_query, $post; /** * Check Jetpack Infinite Scroll * if it's active then disable pagination */ if ( class_exists( 'Jetpack', false ) ) { $jetpack_active_modules = get_option('jetpack_active_modules'); if ( $jetpack_active_modules && in_array( 'infinite-scroll', $jetpack_active_modules ) ) { return false; } } // Don't print empty markup on single pages if there's nowhere to navigate. if ( is_single() ) { $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true ); $next = get_adjacent_post( false, '', false ); if ( ! $next && ! $previous ) return; } // Don't print empty markup in archives if there's only one page. if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) ) return; $nav_class = 'site-navigation paging-navigation'; if ( is_single() ) $nav_class = 'site-navigation post-navigation'; ?> <nav role="navigation" id="<?php echo $nav_id; ?>" class="<?php echo $nav_class; ?>"> <h1 class="assistive-text"><?php _e( 'Post navigation', 'catcheverest' ); ?></h1> <?php if ( is_single() ) : // navigation links for single posts ?> <?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'catcheverest' ) . '</span> %title', $in_same_term = true, $excluded_terms = '', $taxonomy = 'category' ); ?> <?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'catcheverest' ) . '</span>', $in_same_term = true, $excluded_terms = '', $taxonomy = 'category' ); ?> <?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?> <?php if ( get_next_posts_link() ) : ?> <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'catcheverest' ) ); ?></div> <?php endif; ?> <?php if ( get_previous_posts_link() ) : ?> <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'catcheverest' ) ); ?></div> <?php endif; ?> <?php endif; ?> </nav><!-- #<?php echo $nav_id; ?> --> <?php } endif; // catcheverest_content_nav
Thanks for your all your help!
July 24, 2014 at 9:58 am #41366 -
AuthorPosts
- The topic ‘Limit Previous & Next Post Links to Articles in Same Category’ is closed to new replies.