[英]Exclude posts from the_post_navigation() by category
I am using the the_post_navigation()
function in WordPress like this: 我在WordPress中使用
the_post_navigation()
函数,如下所示:
<?php the_post_navigation( array(
'prev_text' => __( 'Previous item'),
'next_text' => __( 'Next item'),
)); ?>
This navigation goes through all my posts, but I want to exclude the posts that contain the category 'footer'. 此导航会浏览我的所有帖子,但我想排除包含“页脚”类别的帖子。 How do I do this?
我该怎么做呢?
I have used this to let the page redirects itself when the single.php goes to a post with the category 'footer': 当single.php转到带有“footer”类别的帖子时,我用它来让页面重定向:
if(in_category('footer')){
$next_post = get_next_post();
$location = get_permalink( $next_post->ID );
wp_redirect( $location );
exit;
} else {}
(Works only when places above get_header();
. Not the most beautiful solution, but it works (only for next post unfortunately) (只有在
get_header();
以上的地方才有效get_header();
。不是最漂亮的解决方案,但它有效(不幸的是仅适用于下一篇文章)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.