Archived topic
Next / Previous Post based within category
39 replies · Started by Michael on September 18, 2020
Oh and also the thumbnails on the CPT posts are taken from the current CPT.
See link
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.
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.
Awesome! I'm sure it'll be helpful to others :)
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) ?
Is there a specific link where I can see that happening?
Hi Tom, examples in the private information area. Also CPT are showing from different categories also.
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.
Best thing to do there is look into the taxonomy name. If the name is correct, in_same_term should work fine.