【问题标题】:How to exclude some Categories from next_post_link and previous_post_link (Wordpress)?如何从 next_post_link 和 previous_post_link (Wordpress) 中排除某些类别?
【发布时间】:2017-02-08 18:29:08
【问题描述】:

我尝试从帖子导航中排除某些类别(next_post_link 和 previous_post_link),但它不起作用。我需要帮助。

我想为这个函数使用functions.php。

有一个很好的功能可以从“类别小部件”中排除类别:

function ds_exclude_widget_categories($args) {
  $exclude = '1,26,28';
     $args['exclude'] = $exclude;
  return $args;
}
add_filter('widget_categories_args', 'ds_exclude_widget_categories');

这样的功能怎么可能会从帖子导航中排除类别?

问候, 塞巴斯蒂安

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    next_post_linkprevious_post_link 已经有用于排除项目 https://codex.wordpress.org/Function_Reference/next_post_link 的参数

    因此,如果您只想从链接中排除 ID 为 13 的类别,您应该使用类似

    <?php next_post_link( '%link', 'Next post in category', FALSE, '13' ); ?> 
    

    【讨论】:

    • 您好 Ed Dogan,感谢您的帮助。
    • 我不想更改主题中的文件,也不想创建子主题。我想把它作为functions.php中的过滤器。这可能吗?
    猜你喜欢
    • 1970-01-01
    • 2012-04-13
    • 2021-11-16
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多