繁体   English   中英

如何在Wordpress中查询接下来的2个帖子

[英]How to query the next 2 posts in Wordpress

我正在查询有关当前位置的Wordpress中的下两个帖子。

因此,例如,如果我在帖子#1上,则显示帖子#2 +#3。 如果我在帖子#7上,则显示帖子#8 +#9。 如果可能的话,我也希望这些循环播放,所以如果帖子#9是最后一篇帖子,并且我正在查看帖子#8,我将看到帖子#9 +#1。

有人可以帮我吗?

               <?php
                $args = array(
                    'post_type' => 'project',
                    'orderby' => 'date',
                    'order' => 'DESC',
                    'posts_per_page' => '2'
                );
                $query = new WP_Query( $args );
                ?>
                <?php if ( $query->have_posts() ) : ?>
                    <?php while ( $query->have_posts() ) : $query->the_post(); ?>

                        <div class="unit one-half">
                            <figure>
                                <?php if ( has_post_thumbnail() ) { 
                                      the_post_thumbnail();
                                } ?>
                            </figure>
                            <figcaption>
                                <h4><?php the_title(); ?></h4>
                                <h5><?php the_excerpt(); ?></h5>
                                <h6><a href="<?php the_permalink(); ?>">Read More</a></h6>
                            </figcaption>
                        </div>

                    <?php endwhile; ?>
                <?php endif; ?>
                <?php wp_reset_postdata(); ?>
<?php
    $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;

    $args = array (
        'post_type' => 'post',
        'posts_per_page' => '2',
        'paged' => $paged,
        );  
    $wp_query = new WP_Query($args);

    while ($wp_query->have_posts()): $wp_query->the_post();
    get_the_title();
    endwhile;

    global $wp_query;

    $big = 999999999; // need an unlikely integer

    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages
    ) );
?>

暂无
暂无

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

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