Community Forums › Forums › Archived Forums › Design Tips and Tricks › prev/next links for one category
- This topic has 7 replies, 2 voices, and was last updated 8 years, 8 months ago by Brad Dalton.
-
AuthorPosts
-
August 11, 2015 at 11:59 am #162048savannahchikMember
I'd like the previous/next post links to only show posts from the category of the post that's being viewed. I searched the forum but probably didn't do a good search because I got a *ton* of posts. I paged through the first couple and then decided to try a post of my own. I apologize if this has been asked/answered. Thanks!
August 11, 2015 at 12:22 pm #162056Brad DaltonParticipantThere's a parameter which you can change in the function which does that.
Set the 3rd parameter to true https://codex.wordpress.org/Function_Reference/next_post_link
in_same_term
(boolean) (optional) Indicates whether next 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 next post link will lead to the next post in any of those terms.Default: false
Also, Nick did post the code for this some time ago. Might be hard to find otherwise you can grab it from the post.php file in Genesis > lib > structure.
August 12, 2015 at 6:04 am #162127savannahchikMemberThanks for giving me the function name to look for!
After getting this response i tried updating next_post_link but i was unsuccessful. Having the call though, I was able to find this post that helped me out. Specifically (in case anyone else needs it), I added a few lines to functions.php
function genesis_post_navigation() { if ( is_single ( ) ) { ?> <div id="prev-next"> <div class="prev-link">← <?php previous_post_link('%link', '%title', TRUE); ?> </div> <div class="next-link">→ <?php next_post_link('%link', '%title', TRUE); ?> </div> </div> <?php } } add_action('genesis_before_comments', 'genesis_post_navigation');
and then styled it in style.css
This puts the prev/next links between the post and the comments (because i used the genesis_before_comments hook). I played around with where it worked and this felt the best for my site.
Thanks again for your help - having the function name saved me A LOT of searching and reading!
August 12, 2015 at 6:15 am #162129Brad DaltonParticipantI would use that in the code from genesis > lib > structure > post.php.
next_post_link('%link', '%title', TRUE); previous_post_link('%link', '%title', TRUE);
Any reason you didn't want to use the code from Genesis?
August 12, 2015 at 9:13 am #162160savannahchikMemberi didn't realize i had access to those variable in post.php! i just reversed my changes and did what you quoted in post.php and it worked like a charm - thank you!
August 12, 2015 at 9:18 am #162162Brad DaltonParticipantRather then edit the code in post.php, please copy it to your child theme, change the function name and add a hook for positioning otherwise you'll lose those changes when Genesis updates.
August 12, 2015 at 10:01 am #162167savannahchikMemberok I'm not quite sure what you're suggesting (I'm still new to Genesis).
- I don't have a post.php for my child theme.
- Should I just create a new one and only have the one function in there?
- I think it will have the same code I pasted above, but in the child theme's post.php
Did I get that right?
August 12, 2015 at 10:07 am #162168Brad DaltonParticipant -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.