Im using the next post link function of WP to show next and previous navigation links to the “next post in same category” all good with this…the issue i have is that when I’m in the “last” post of a category, the “NEXT” link appears anyway and doing what i dont want: linking to a different category 1st post. the same with the 1st post of a category, when browsing the first post of a category the “PREVIOUS” link appears linking to previous post of a another different category… I would like that in the 1st and last post, this links aren’t shown.
<div id="nav-above" class="navigation">
<div class="nav-previous"><?php previous_post_linknext_post_link( '%link', '<span class="meta-nav">' .
_x( '◄ Previous', 'Previous post link','category' ,TRUE ) . '</span>' ); ?></div>
<div class="nav-next"><?php next_post_link( '%link', '<span class="meta-nav">' . _x( 'Next ► ', 'Next post link', 'category',TRUE ) . '</span>' ); ?> </div>
</div><!-- #nav-above -->
You need to test whether there is a next or previous post by using the get_previous_post_link and get_next_post_link functions. For example: