This topic has 4 replies, 3 voices, and was last updated 7 years by Radu.

  • Author
  • #170014
     kffaner
    Participant

    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.

    #170121
     Laura
    Moderator

    Hello, 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 solution

    Laura 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 🙂

    #170579
     Radu
    Moderator

    Hi,

    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 CODE
    
    if ( ! 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 solution
    #170584
     kffaner
    Participant

    Just 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!

    #170731
     Radu
    Moderator

    Hi,

    On then

    Cheers
    R

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
Viewing 5 posts - 1 through 5 (of 5 total)

The forum ‘Bugs & Issues’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?