简体   繁体   中英

Linking category posts (Wordpress)

I have a category in Wordpress called News and would like to link to the next news page when viewing a story.

This is the existing code but will link to all posts, what should I add to make it just posts in the News category?

<div id="page-navi">
<div class="button previous"><?php previous_post_link('%link') ?></div>
<div class="button next"><?php next_post_link('%link') ?></div>
   </div><!-- page-navi -->

Many thanks

From the WordPress documentation :

previous_post_link($format, $link, $in_same_cat = false, $excluded_categories = '')

So just add true as a third parameter:

<div id="page-navi">
<div class="button previous"><? previous_post_link('%link', 'Previous in category', true) ?></div>
<div class="button next"><?php next_post_link('%link', 'Next in category', true) ?></div>
   </div><!-- page-navi -->

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM