Community Forums › Forums › Archived Forums › Design Tips and Tricks › Exclude/include Categories in Previous/Next link navigation
Tagged: categories, next, previous
- This topic has 5 replies, 3 voices, and was last updated 6 years, 11 months ago by
dreamdancer.
-
AuthorPosts
-
January 20, 2016 at 1:36 pm #177029
dan121
MemberI have my blog divided into two parts using category pages.
Using the custom field query_args, one page shows posts from one category, and the other page shows all the posts except for that one category.
This works fine, but I've run into a problem with the previous/next navigation links at the end of the single entries: the navigation links ignore the categories.
Navigation links are added with this in functions.php: add_action( 'genesis_entry_footer', 'genesis_prev_next_post_nav' );
I need some way to limit the navigation links to a specific category on one set of posts, and to exclude that category on the other set of posts.
For example, if I have categories of apples, oranges, grapes and automobiles:
Category page Fruit shows all the fruit posts and excludes auto posts, and next/prev links only go to fruit posts.
Category page Cars only shows auto posts, and next/prev links only go to auto posts.January 21, 2016 at 8:40 am #177078Brad Dalton
ParticipantYou'll need to use the parameters for the previous and next post functions.
https://codex.wordpress.org/Function_Reference/previous_post_link
https://codex.wordpress.org/Function_Reference/next_post_link
January 21, 2016 at 4:09 pm #177116Brad Dalton
ParticipantI think you mean in same term which is a paremater you can use in each function however you'll need to rebuild the function because there is no filter added to the genesis_prev_next_post_nav function in genesis.
in_same_term
(boolean) (optional) Indicates whether previous post must be within the same taxonomy term as the current post. If set to 'true', only posts from the current taxonomy term will be displayed. If the post is in both the parent and subcategory, or more than one term, the previous post link will lead to the previous post in any of those terms.
true
false
January 25, 2016 at 8:00 am #177433dan121
Memberyeah, I had to ditch genesis_prev_next_post_nav function and use this code:
add_action('genesis_entry_footer', 'custom_pagination_links', 15 ); function custom_pagination_links() { if( !is_single() ) return; ?> <div id="prev-next"> <?php previous_post_link( '<div class="prev-link">← Previous<br />%link</div>', '%title', TRUE ); next_post_link( '<div class="next-link">Next →<br />%link</div>', '%title', TRUE ); ?></div> <?php }January 25, 2016 at 12:02 pm #177470Brad Dalton
ParticipantFebruary 26, 2019 at 4:41 pm #489735dreamdancer
ParticipantI have been looking all over for how to do this. Thanks so much!!!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.