简体   繁体   English

在Wordpress中,如何显示下一个和上一个帖子

[英]In wordpress, how to show next and previous post

I am able to display next and previous post in worspress but unable to show second-previous or third-previous || 我可以在worpress中显示下一个和上一个帖子,但无法显示第二个或上一个|| second-next or third-next like 第二个下一个或第三个下一个

1 - I want to show this too 1- 我也想展示这个
2 - this is showing 2-显示
3 - My Current post 3- 我当前的帖子
4 - This is showing 4-显示
5 - I want to show this too 5- 我也想展示这个

any help would be appreciated. 任何帮助,将不胜感激。 In the and I am showing you my code so you can judge. 在中,我向您展示我的代码,以便您进行判断。

CODE: 码:

<?php $next = get_permalink(get_adjacent_post(false,'',false)); if
($next != get_permalink()) { ?><a href="<?php echo $next; ?>">
    <li class="col-xs-12 col-md-4">
        <div class="article">
            <div class="contain-image">
            <?php $nextPost = get_next_post(true); $nextthumbnail = get_the_post_thumbnail($nextPost->ID); echo $nextthumbnail; ?>
            </div>
            <div class="content">
                <div class="double-content">
                    <div class="information">
                        <span class="category"><?php echo get_cat_name(1);?></span>
                        <span class="time"><?php the_time('M j, Y') ?></span>
                    </div>
                    <div class="title">
                        <?php next_post_link('%link', "%title", TRUE); ?>
                    </div>
                    <p>
                        <?php 
                        $Nextpost = get_next_post($id);
                        echo apply_filters(‘the_content’, $Nextpost->post_content);
                        ?>
                    </p>
                </div>
            </div>
        </div>
    </li>
</a>
<?php } ?>
<?php $prev = get_permalink(get_adjacent_post(true,'',true)); if
($prev != get_permalink()) { ?><a href="<?php echo $prev; ?>">
    <li class="col-xs-12 col-md-4">
        <div class="article">
            <div class="contain-image">
            <?php $prevPost = get_previous_post(true); $prevThumbnail = get_the_post_thumbnail($prevPost->ID); echo $prevThumbnail; ?>
            </div>
            <div class="content">
                <div class="double-content">
                    <div class="information">
                        <span class="category"><?php echo get_cat_name(1);?></span>
                        <span class="time"><?php the_time('M j, Y') ?></span>
                    </div>
                    <div class="title">
                        <?php previous_post_link('%link', "%title", TRUE); ?>
                    </div>
                    <p>
                    <?php 
                        $Prevpost = get_previous_post($id);
                        echo apply_filters(‘the_content’, $Prevpost->post_content);
                        ?>
                    </p>
                </div>
            </div>
        </div>
    </li>
</a>
<?php } ?>

WordPress provides several navigational template tags to make it easy for visitors to surf your pages. WordPress提供了几个导航模板标签,以使访问者轻松浏览您的页面。 There are basically two different types of template tags used for chronological post navigation: 基本上,有两种不同类型的模板标签用于按时间顺序排列的帖子导航:

posts_nav_link() – for navigating various archive (non-single) pages
previous_post_link() & next_post_link() – for navigating single-post pages


<?php $posts = query_posts($query_string); if (have_posts()) : while (have_posts()) : the_post(); ?>

    <?php previous_post_link(); ?> | <?php next_post_link(); ?>

<?php endwhile; endif; ?>

try this: 尝试这个:

    global $post;
    $post_curr = $post;

    //get last post
    $post_last1 = get_previous_post();
    setup_postdata($post_last1);
    //get second last post
    $post_last2 = get_previous_post();


    setup_postdata($post_curr);
    //get next post now
    $post_next1 = get_next_post();
    setup_postdata($post_next1);
    //get second next post
    $post_next2 = get_next_post();

    //reset current post data
    setup_postdata($post_curr);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM