-
Author
-
August 9, 2017 at 05:01 #170014kffanerParticipant
i want to restrict the navigation for posts to the category that the post is on. Right now this is what happens:
If lets say i have 3 posts from category on animals and 1 post from category on numbers, however i added the numbers category post before the last post on animals category, then when i navigate to post 2 of animals category, the next button will lead me to the post on numbers category instead of the 3rd post of animals category.
Could you give me a code snippet and some links to instructions how i can restrict the navigation to stick with the current category of the post rather than navigate through posts based on date of publish? Thank you.
August 9, 2017 at 23:57 #170121LauraModeratorHello, will assign the ticket to a higher support level who can help and advise you in your query.
Thanks! ?Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionLaura Solanes - Graphic Designer and Web Designer
Please be patient as I try to answer each topic as fast as i can.
If you like the theme or the support you've received please consider leaving us a review on Themeforest!
Always happy to help you 🙂
August 14, 2017 at 15:45 #170579RaduModeratorHi,
It’s narrowed by default to the current category of the post, pay attention to the posts to not be in two categories, any way you can use the next code that will force the function to run only for the current category.
COPY CODEif ( ! function_exists( 'kleo_post_nav' ) ) : /** * Display navigation to next/previous post when applicable. * * @since Kleo 1.0 * * @return void */ function kleo_post_nav( $same_cat = true ) { // Don't print empty markup if there's nowhere to navigate. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( $same_cat, '', true ); $next = get_adjacent_post( $same_cat, '', false ); if ( ! $next && ! $previous ) { return; } ?> <nav class="pagination-sticky member-navigation" role="navigation"> <?php if ( is_attachment() ) : previous_post_link( '%link', __( '<span id="older-nav">Go to article</span>', 'kleo_framework' ) ); else : if ( $previous ) { previous_post_link( '%link', '<span id="older-nav"><span class="outter-title"><span class="entry-title">' . $previous->post_title . '</span></span></span>', $same_cat ); } if ( $next ) { next_post_link( '%link', '<span id="newer-nav"><span class="outter-title"><span class="entry-title">' . $next->post_title . '</span>', $same_cat ); } endif; ?> </nav><!-- .navigation --> <?php } endif;
The function needs to be pasted in wp-content/themes/kleo-child/functions.php
NOTE: Child theme needs to be installed and activated.
Cheers
R.Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionAugust 14, 2017 at 16:01 #170584kffanerParticipantJust an fyi – it is NOT doing that by default, i double checked to make sure its in one category and not in both. I would suggest adding this code as default in the next theme update.
But with this code you provided it works like a charm now!
August 15, 2017 at 18:32 #170731RaduModeratorHi,
On then
Cheers
RHi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution -
AuthorPosts
The forum ‘Bugs & Issues’ is closed to new topics and replies.