【问题标题】:Wordpress get_next_post set the categorywordpress get_next_post 设置类别
【发布时间】:2016-08-01 19:51:57
【问题描述】:

是否可以在 Wordpress 中设置 get_next_post 中使用的类别。

我的帖子可以包含多个类别。

在single.php 页面上显示我想显示下一个和上一个帖子的帖子。

我在 single.php 中有我想要选择的类别,那么如何在 get_next_post 中使用它

    $the_cat = 'latest';

    $next_post = get_next_post($in_same_term = true, $excluded_terms = '', $taxonomy = $the_cat); 

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    正如我看到的文档编号。

    $分类 (字符串)(可选)分类法,如果 $in_same_term 为真。在 WordPress 3.8 中添加。 默认值:'类别'

    如我所见,如果您将$in_same_term 设置为false,那么您可以更改$taxonmy

    我认为,这可能是您的一种解决方法,未经测试,只是一个想法:

    <?php
    while ($next_post = get_next_post()) {
        if (!empty($next_post) && $next_post->catID == 'what you want') {
            ?>
            <a href="<?php echo get_permalink($next_post->ID); ?>"><?php echo $next_post->post_title; ?></a>    
            <?php
        }
    }
    ?>
    

    【讨论】:

      【解决方案2】:

      按照法典中的内容https://codex.wordpress.org/Function_Reference/get_next_post...

      在您的页面循环中...

      $category = get_the_category();
      $category_name = $category[0]->name:
      

      然后通过...获取您的下一篇文章

      $next_post = get_next_post(true, null, $category_name); 
      

      【讨论】:

        猜你喜欢
        • 2011-02-07
        • 1970-01-01
        • 1970-01-01
        • 2017-05-06
        • 1970-01-01
        • 2012-08-20
        • 1970-01-01
        • 2018-09-28
        • 1970-01-01
        相关资源
        最近更新 更多