Check out the template tag previous_post_link(). The third parameter in the set allows you to specify whether the previous post that it links to should be from the same category – set to true to enable this feature. A similar tag exists for next post as well.
I hope this helps!
Yes that helped thanks (=, but now i have another problem, my previous and next post links are the same, meaning they lead to the same post: here is the code i was editing
if (!function_exists(‘theme_get_previous_post_link’)){
function theme_get_previous_post_link($format=’« %link’, $link=’%title’, $in_same_cat = true, $excluded_categories = ”) {
return theme_get_adjacent_post_link($format, $link, $in_same_cat = true);
}
}
if (!function_exists(‘theme_get_next_post_link’)){
function theme_get_next_post_link($format=’%link »’, $link=’%title’, $in_same_cat = true, $excluded_categories = ”) {
return theme_get_adjacent_post_link($format, $link, $in_same_cat = true);
}
}
Well, it looks like whatever theme-specific implementation of previous_post_link that you’re using calls the same function for getting an adjacent post, so unless that function has another parameter for specifying whether to get the previous post or next post, I’m not sure how it would be distinguishing between previous and next post. I’d take a look further at the theme_get_adjacent_post_link method and see if there’s any missing parameters or some other way to distinguish between a previous post and next post. If not, you can try falling back to the methods that are built in to WordPress.