WP link pages from same category in the previous next navigation links

This article was written by in August 20, 2014, & may not be posted on other sites!
Original source url for this article: WP link pages from same category in the previous next navigation links

WP link pages from same category in the previous next navigation links.
The default previous next links at the bottom of single posts can be altered. This is how to link pages only from the same category as the post, in the previous next navigation links.

 

WP link pages from same category in the previous next navigation links

The default previous next navigation will link to posts within all categories. To have the previous next navigation only linking to pages within the same category as the post, you need to find the previous – next navigation function and change it. The code you are looking for is probably located in the single.php or single.php. Look for the navigation links function right after the content. The previous – next navigation function links in your theme might look something like this:
<?php twentythirteen_post_nav(); ?>

Just replace the code with
<?php previous_post_link('%link', '%title', TRUE); ?>
<?php next_post_link('%link', '%title', TRUE); ?>

 

Put the navigation links in divs for easier styling
For easier styling, put the code inside divs, something like this:

<div id="single-navigation">
<div id="previous"><?php previous_post_link('%link', '%title', TRUE); ?></div>
<div id="next"><?php next_post_link('%link', '%title', TRUE); ?></div>
</div>

 

Replace the links post titles with any other text
To replace the post title as links with for example “next article” & “previous article”, change the second variable, something like this:
<?php previous_post_link('%link', 'previous article', TRUE); ?>
<?php next_post_link('%link', 'next article', TRUE); ?>

 

Spread the word

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *