[Resolved] Next/Previous post links on CPT

Home Forums Support [Resolved] Next/Previous post links on CPT

Home Forums Support Next/Previous post links on CPT

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #998976
    David
    Staff
    Customer Support

    So if you go to Blog > Customizer > Layout under Content select the Single tab and uncheck: Display post navigation … this doesn’t work?

    https://docs.generatepress.com/article/blog-content-layout/#single

    #998982
    Matt

    No, I just deleted CSS: .nav-links { display: none; }

    then tried your way, and the Next/previous are back again!

    #998993
    David
    Staff
    Customer Support

    If you want to start a new topic where you can share your site privately using the Site URL i can take a look as to why unchecking Display post navigation isn’t working.

    #1361740
    jasond

    I had 2 filters to customize the prev/next texts on Post, how to add another filter for CPT?

    Many thanks

    add_filter( 'next_post_link', function( $output, $format, $link, $post ) {
      	if ( ! $post ) {
    	  return '';
    	}
      
    	return sprintf(
    		'<div class="nav-next"><span class="next"><a href="%1$s" title="%2$s">Next Article</a></span></div>',
    	  	get_permalink( $post ),
    	  	$post->post_title
    	);
    }, 10, 4 );
    
    add_filter( 'previous_post_link', function( $output, $format, $link, $post ) {
      	if ( ! $post ) {
    	  return '';
    	}
      
    	return sprintf(
    		'<div class="nav-previous"><span class="prev"><a href="%1$s" title="%2$s">Previous Article</a></span></div>',
    	  	get_permalink( $post ),
    	  	$post->post_title
    	);
    }, 10, 4 );
    #1361884
    David
    Staff
    Customer Support

    Hi there,

    you can introduce more if condtions – for example:

    add_filter( 'next_post_link', function( $output, $format, $link, $post ) {
    
      if ( ! $post ) {
        return '';
    
      } elseif ( is_singular( 'book' ) {
        // return your CPT nav link content here
      }
      // return standard post
      return sprintf(
      '<div class="nav-next"><span class="next"><a href="%1$s" title="%2$s">Next Article</a></span></div>',
        get_permalink( $post ),
        $post->post_title
      );
    }, 10, 4 );
    #1459216
    onalti

    I tried it for custom post typle but it doesn’t work.

    add_filter( 'next_post_link', function( $output, $format, $link, $post ) {
    
      if ( ! $post ) {
        return '';
    
      } elseif ( is_singular( 'book' ) {
        // return your CPT nav link content here
      }
      // return standard post
      return sprintf(
      '<div class="nav-next"><span class="next"><a href="%1$s" title="%2$s">Next Article</a></span></div>',
        get_permalink( $post ),
        $post->post_title
      );
    }, 10, 4 );
    #1459584
    David
    Staff
    Customer Support

    Hi Onalti,

    could you raise a new topic explaining what you require as this topic is a mass of various requests.

Viewing 7 posts - 16 through 22 (of 22 total)
  • You must be logged in to reply to this topic.