Support » Theme: Receptar » Navigation Arrows

  • Resolved el2adiii

    (@el2adiii)


    Hello, Thank you for the theme. I’ve customized everything I want using it. It’s really amazing.
    I’ve a question,
    I have a tag page that has posts within it, when I go to the first post, the navigation arrows to the next post send me to another tag, it sends me to the newer post. But I want to limit it to this specific tag.
    So when I go to a post in this tag, I can only navigate within it and can’t navigate to newer posts from other tags or categories.
    How can I do this?
    Many thanks.

Viewing 1 replies (of 1 total)
  • Hi,

    Thank you, I’m glad you like the theme 🙂

    There is no real easy way around this. You need to copy the receptar_post_nav() function from the theme to your child theme’s functions.php file and then modify the get_adjacent_post WordPress function used within to get links from the same term only.

    Basically, just put this into your child theme’s functions.php file and it should work:

    function receptar_post_nav() {
    	//Requirements check
    		if ( ! is_singular() || is_page() ) {
    			return;
    		}
    	//Helper variables
    		$output = $prev_class = $next_class = '';
    		$previous = ( is_attachment() ) ? ( get_post( get_post()->post_parent ) ) : ( get_adjacent_post( true, '', true ) );
    		$next     = get_adjacent_post( true, '', false );
    	//Requirements check
    		if (
    				( ! $next && ! $previous )
    				|| ( is_attachment() && 'attachment' == $previous->post_type )
    			) {
    			return;
    		}
    		$links_count = absint( (bool) $next ) + absint( (bool) $previous );
    	//Preparing output
    		if ( $previous && has_post_thumbnail( $previous->ID ) ) {
    			$prev_class = " has-post-thumbnail";
    		}
    		if ( $next && has_post_thumbnail( $next->ID ) ) {
    			$next_class = " has-post-thumbnail";
    		}
    		if ( is_attachment() ) {
    			$output .= get_previous_post_link(
    					'<div class="nav-previous nav-link' . esc_attr( $prev_class ) . '">%link</div>',
    					wp_kses(
    						__( '<span class="post-title"><span class="meta-nav">Published In: </span>%title</span>', 'receptar' ),
    						array( 'span' => array( 'class' => array() ) )
    					)
    				);
    		} else {
    			$output .= get_next_post_link(
    					'<div class="nav-next nav-link' . esc_attr( $next_class ) . '">%link</div>',
    					wp_kses(
    						__( '<span class="post-title"><span class="meta-nav">Next: </span>%title</span>', 'receptar' ),
    						array( 'span' => array( 'class' => array() ) )
    					)
    				);
    			$output .= get_previous_post_link(
    					'<div class="nav-previous nav-link' . esc_attr( $prev_class ) . '">%link</div>',
    					wp_kses(
    						__( '<span class="post-title"><span class="meta-nav">Previous: </span>%title</span>', 'receptar' ),
    						array( 'span' => array( 'class' => array() ) )
    					)
    				);
    		}
    		if ( $output ) {
    			$output = '<nav class="navigation post-navigation links-count-' . $links_count . '" role="navigation"><h1 class="screen-reader-text">' . esc_html__( 'Post navigation', 'receptar' ) . '</h1><div class="nav-links">' . $output . '</div></nav>';
    		}
    	//Output
    		echo apply_filters( 'wmhook_receptar_post_nav_output', $output );
    }
    

    Regards,

    Oliver

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.