Black Friday Sale! Get up to $30 off GP Premium! Learn more ➝

[Resolved] Next / Previous Post based within category

Home Forums Support [Resolved] Next / Previous Post based within category

Home Forums Support Next / Previous Post based within category

Viewing 10 posts - 31 through 40 (of 40 total)
  • Author
    Posts
  • #1452760
    Michael

    Oh and also the thumbnails on the CPT posts are taken from the current CPT.

    See link

    #1452939
    Tom
    Lead Developer
    Lead Developer

    You should just be able to do this for everything:

    add_filter( 'generate_post_navigation_args', function( $args ) {
        if ( is_single() ) {
            $prevPost = get_previous_post( true, '', 'wpdmcategory' );
            $prevThumbnail = isset( $prevPost ) ? get_the_post_thumbnail( $prevPost->ID ) : '';
            $nextPost = get_next_post( true, '', 'wpdmcategory' );
            $nextThumbnail = isset( $nextPost ) ? get_the_post_thumbnail( $nextPost->ID ) : '';
    
            $args['previous_format'] = '<div class="nav-previous">' . $prevThumbnail . generate_get_svg_icon( 'arrow' ) . '<span class="prev" title="' . esc_attr__( 'Previous', 'generatepress' ) . '">%link</span></div>';
            $args['next_format'] = '<div class="nav-next">' . $nextThumbnail . generate_get_svg_icon( 'arrow' ) . '<span class="next" title="' . esc_attr__( 'Next', 'generatepress' ) . '">%link</span></div>';
        }
    
        if ( is_singular( 'wpdmpro' ) ) {
            $args['taxonomy'] = 'wpdmcategory';
            $args['in_same_term'] = true;
        }
    
        return $args;
    } );
    
    add_filter( 'generate_footer_meta_post_types', function( $types ) {
        $types[] = 'wpdmpro';
    
        return $types;
    } );

    This should:

    1. Add thumbnails to your post navigation if they exist.
    2. Set the wpdmcategory taxonomy in your wpdmpro post type, and make it so the post navigation stays within the current term.
    3. Tells GeneratePress to add footer post meta to your custom post type.

    #1453656
    Michael

    Hi Tom, pleased to say that it does indeed work. I had to enable the stay in category function as it wasn’t doing that. Also even with that running the CPT doesn’t stick to same category. Additionally the CPT thumbnails for next and previous are showing as the current CPT thumbnail on either side.

    Have to say it looks great, just need to get these little niggles sorted. Again, appreciate the support here, am hoping it might be useful for anyone else with a similar problem.

    #1454144
    Tom
    Lead Developer
    Lead Developer

    Awesome! I’m sure it’ll be helpful to others πŸ™‚

    #1455226
    Michael

    I’m sure it will πŸ™‚ , how can I fix the same thumbnail issue for the CPT ? uses the same thumb for next and previous, and the thumb it uses is that of the current post (download in this case) ?

    #1455786
    Tom
    Lead Developer
    Lead Developer

    Is there a specific link where I can see that happening?

    #1455795
    Michael

    Hi Tom, examples in the private information area. Also CPT are showing from different categories also.

    #1456117
    Tom
    Lead Developer
    Lead Developer
    #1456677
    Michael

    Brilliant, thank you so so much! The CPT aren’t staying within category, but I won’t bother you anymore. I know you’ll be fed up of this. πŸ™‚

    I’ll see if I can try different things to get that to work. Really appreciate all your work on this Tom. Just wish I knew more. I do try though.

    #1457299
    Tom
    Lead Developer
    Lead Developer

    Best thing to do there is look into the taxonomy name. If the name is correct, in_same_term should work fine.

Viewing 10 posts - 31 through 40 (of 40 total)
  • You must be logged in to reply to this topic.