为什么我的CPT不显示下一个和以前的链接在单一的帖子视图


Why are my CPT not showing next and previous links on single post view?

不知有没有人能帮上忙!

我有一个函数,得到下一个/上一个链接的帖子,它是包含在每个帖子类型的模板内作为全局导航到和从帖子。下面是它的代码:

if ( ! function_exists( 'theme_post_nav' ) ) :
/**
 * Display navigation to next/previous post when applicable.
 */
function theme_post_nav() {
    ?>
    <?php
    // Don't print empty markup if there's nowhere to navigate.
    $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
    $next     = get_adjacent_post( false, '', false );
    if ( ! $next && ! $previous ) {
        return;
    }
    ?>
    <nav class="navigation post-navigation <?php if ( 'supporter' == get_post_type() ) { ?>supporter<?php } ?>" role="navigation">
        <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'theme' ); ?></h1>
        <div class="nav-links">
            <?php
                previous_post_link( '<div class="nav-previous">%link</div>', _x( '<span class="meta-nav icon icon_arrow-backward"></span> %title', 'Previous post link', 'theme' ) );
                next_post_link(     '<div class="nav-next">%link</div>',     _x( '%title <span class="meta-nav icon icon_arrow-forward"></span>', 'Next post link',     'theme' ) );
            ?>
        </div><!-- .nav-links -->
    </nav><!-- .navigation -->
    <?php
}
endif;

这将输出正常帖子的正确导航,但当它进入自定义帖子类型时,它只显示当前帖子的链接。

在我的single-support .php中我有:

        <?php get_template_part( 'content', 'single' ); ?>
        <?php
            // If comments are open or we have at least one comment, load up the comment template
            if ( comments_open() || '0' != get_comments_number() ) :
                comments_template();
            endif;
        ?>
    <?php endwhile; // end of the loop. ?>
    </div>
    <?php get_sidebar(); ?>
</main><!-- #main -->

然后在页脚,我有一个获取分页的函数:

我想知道这里是否有什么非常明显的东西?

你的函数theme_post_nav()在循环内吗?

previous_post_link()和next_post_link()都应该在循环内才能工作。

更多;http://codex.wordpress.org/Template_Tags/previous_post_link