Archived topic
How to restrict Next & Previous post links to category?
3 replies · Started by karl on March 13, 2016
Hi,
In the posts at the bottom there are links to the next post and previous post. If the next post is in a different category from the current one, how do you get it to stop the next/previous link from showing?
I have tried putting this in the under content section in hook:
<?php previous_post_link('<h6 style="float:left;">%link</h6>', 'Previous', TRUE); ?>
<?php next_post_link( '<h6 style="float:right;">%link</h6>', 'Next', TRUE ); ?>
and also using css to make the default links invisible:
.post-navigation {
display: none !important;
}
.cat-links {
display: none !important;
}
The issue with this is that these links are visible from the page where you can see the exerts of all my posts. I don't want to display these links here because it looks cluttered and is not needed. Any ideas?
Much appreciated. Awesome software by the way!
Manage to solve this by changing this a bit: https://gist.github.com/generatepress/bb5a62c2a94b94bedad0 (setting to TRUE).
How would I change it so that it has the arrow after next? At the moment it says >Next. I want it to say Next> Struggling to see how to do this.
Glad you found the solutions! Thanks for posting :)
You can also achieve the category specific navigation with this filter instead of that entire function: https://generatepress.com/forums/topic/nextprevious-links-within-category-only/#post-157100
