Site logo

Archived topic

Site Template: Crypo Theme - Element function

5 replies · Started by Joakim on July 30, 2021

Viewing posts 1–6 of 6

Hi!

When using your "crypto theme template" is it possible to make the element "Post navigation" to only navigate posts within that specific category. So in other words based on what category that specific post is on, a dynamic approach to show similair posts.

Best Regards

Hi there,

You can play around with David's snippet here - https://generatepress.com/forums/topic/display-post-navigation-to-show-previous-and-next-for-particular-category/#post-1751022

But the tricky part will be how you specify which category will the navigation have to navigate through if posts belong to multiple categories.

My suggestion would be to assign a primary category to each posts or keep them to only 1 post and then tweak the PHP snippet to fetch the primary category and use is as the category to navigate from.

Hi Elvin!

And thanks for the quick response.
I only use one category for each post so then it shoulden't be a problem.

I tried to add this php snippet that you were refering to from David:

"add_filter( 'generate_post_navigation_args', function( $args ) {
if ( is_single() && ! in_category('your_category_slug') ) {
// Display default post navigation if NOT in category
$args['previous_format'] = '

';
$args['next_format'] = '

';
}
elseif ( is_single() && in_category('your_category_slug') ) {
// Display Next Previous on specifc category
$args['previous_format'] = '

';
$args['next_format'] = '

';
}

return $args;
} );"

However its still not working properly, still shows all categories insteed of the same one as the post itself.

Any ideas?

Hi there,

remove that code.
Then edit the Post Navigation element in Appearance > Elements.
You will need to select each of the headings and buttons and set the 'In Same Term' option for the dynamic text type:

https://www.screencast.com/t/NdknFoPw

Thanks David!

Even better =)
Take care

Glad to be of help

This archived topic is closed to new replies.