从导航中排除发布格式

时间:2015-07-25 作者:Jack Cash

我想从我的单篇帖子底部的导航中排除帖子格式的“图片”。

我如何才能修改以下代码以排除“图像”帖子格式?

if ( ! function_exists( \'sparkling_post_nav\' ) ) :
function sparkling_post_nav() {
    // 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" role="navigation">
        <h1 class="screen-reader-text"><?php _e( \'Post navigation\', \'sparkling\' ); ?></h1>
        <div class="nav-links">
            <?php
                previous_post_link( \'<div class="nav-previous">%link</div>\', _x( \'<i class="fa fa-chevron-left"></i> %title\', \'Previous post link\', \'sparkling\' ) );
                next_post_link(     \'<div class="nav-next">%link</div>\',     _x( \'%title <i class="fa fa-chevron-right"></i>\', \'Next post link\',     \'sparkling\' ) );
            ?>
        </div><!-- .nav-links -->
    </nav><!-- .navigation -->
    <?php
}
endif;

1 个回复
最合适的回答,由SO网友:Derek Herman 整理而成

在函数开头添加:

if ( has_post_format( \'image\' ) ) {
    return;
}

结束