最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Previous_post and Next_post - Custom Post Type

programmeradmin2浏览0评论

I have a custom post type and using this function to add for posts, previous and next buttons.

The problem is that within the custom post type, I have subcategories defined by a custom field category.

Is there a way to limit the previous and next post link for items only within the same category of the current post?

 function crunchify_post_navigation(){
    ?>
    <div class="arrowNav">
        <div class="arrowLeft">
            <?php previous_post_link('%link', '&#8606;', FALSE); ?>
        </div>
        <div class="arrowRight">
            <?php next_post_link('%link', '&#8608;', FALSE); ?>
        </div>
    </div>
    <?php
    }

    add_action('wp_footer', 'crunchify_post_navigation');

I have a custom post type and using this function to add for posts, previous and next buttons.

The problem is that within the custom post type, I have subcategories defined by a custom field category.

Is there a way to limit the previous and next post link for items only within the same category of the current post?

 function crunchify_post_navigation(){
    ?>
    <div class="arrowNav">
        <div class="arrowLeft">
            <?php previous_post_link('%link', '&#8606;', FALSE); ?>
        </div>
        <div class="arrowRight">
            <?php next_post_link('%link', '&#8608;', FALSE); ?>
        </div>
    </div>
    <?php
    }

    add_action('wp_footer', 'crunchify_post_navigation');
Share Improve this question asked Mar 1, 2017 at 14:21 JoaMikaJoaMika 6986 gold badges27 silver badges58 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

You want to change the in_same_term value to TRUE as follows:

 function crunchify_post_navigation(){
    ?>
    <div class="arrowNav">
        <div class="arrowLeft">
            <?php previous_post_link('%link', '&#8606;', TRUE); ?>
        </div>
        <div class="arrowRight">
            <?php next_post_link('%link', '&#8608;', TRUE); ?>
        </div>
    </div>
    <?php
    }

    add_action('wp_footer', 'crunchify_post_navigation');

This function must be used within the loop.

https://codex.wordpress/Function_Reference/next_post_link

发布评论

评论列表(0)

  1. 暂无评论