按POST_DATE排序在上一个和下一个帖子分页中不起作用

时间:2021-10-08 作者:Yajuvendra

我为我的单个帖子模板添加了带有缩略图的上一页和下一页,但它没有显示正确的上一页和下一页帖子。此外,看到它通过post ID显示上一个和下一个邮政订单,并试图通过post\\u日期更改订单,但它不起作用。以下是后期导航代码。有人能帮帮我吗。。。

function wpse73190_adjacent_post_sort( $orderby ){
    return "ORDER BY p.post_date DESC LIMIT 1";
}
add_filter( \'get_previous_post_sort\', \'wpse73190_adjacent_post_sort\' );
add_filter( \'get_next_post_sort\', \'wpse73190_adjacent_post_sort\' );

function wpsites_image_nav_links() {
    if (is_singular(\'post\')) {
        $excluded_terms = \'39\';
        echo \'<div class="nav_container">\';
        $prev_post = get_previous_post($excluded_terms);
        $next_post = get_next_post($excluded_terms);
        if (!empty( $prev_post )): ?>
            <?php $prevthumb = get_the_post_thumbnail_url( $prev_post->ID, \'full\' ); ?>
            <?php echo\'<span style="background:url(\'.$prevthumb.\')" class="single-post-nav previous-post-link">\'; ?>
            <a href="<?php echo $prev_post->guid ?>">
            <?php echo "<div id=\'borderLeft\'></div><div class=\'shape\' style=\'left:0; z-index:1; position: absolute; top: -15px;\'>
            <div id=\'curved-corner-bottomleft\'></div>
            <div id=\'curved-corner-topleft\'></div>
            </div>"; ?>   
            <?php echo "<p>".$prev_post->post_title."</p>"; ?>
            </a>
            <?php echo\'</span>\'; ?>
        <?php endif; ?>
        
        <?php if (!empty( $next_post )): ?>
            <?php $nextthumb = get_the_post_thumbnail_url( $next_post->ID, \'full\' ); ?>
            <?php echo\'<span style="background:url(\'.$nextthumb.\')" class="single-post-nav next-post-link">\'; ?>
            <a href="<?php echo esc_url( get_permalink( $next_post->ID ) ); ?>">
            <?php echo "<div id=\'borderRight\'></div><div class=\'shape\' style=\'right:0; z-index:1; position: absolute; top: -15px;\'>
            <div id=\'curved-corner-bottomright\'></div>
            <div id=\'curved-corner-topright\'></div>
            </div>"; ?>
            <?php echo "<p>".esc_attr( $next_post->post_title )."</p>"; ?>
            </a>
            <?php echo \'</span>\'; ?>
        <?php endif; ?>
        <?php echo \'</div>\'; ?>
    <?php  }
}

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

$excluded_terms 应该是第二个参数以获取\\u previous\\u post etc,而不是第一个。也不需要这些过滤器。