开发者

Linking category posts (Wordpress)

开发者 https://www.devze.com 2023-01-14 07:43 出处:网络
I have a category in Wordpress called News and would like to link to the next news page when viewing a story.

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 previ开发者_StackOverflow社区ous"><?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 -->
0

精彩评论

暂无评论...
验证码 换一张
取 消