繁体   English   中英

自定义页面上的Wordpress分页不起作用

[英]Wordpress Pagination on Custom Page not working

我在标准循环/查询中创建了一个自定义帖子类型页面(page-portfolio.php),并为“自定义帖子类型”创建了第二个循环。 在此CPT页面上,我想显示一个分页。 因此,我在这里使用wp_bootstrap_pagination: github

在我的常规“存档页面”上,导航有效,但仅在此起作用。 怎么了? 由于两个循环/查询,是否有任何问题?

     <?php
/**
 * Template Name: Portfolio
 * The template for displaying portfolio posts.
 *
 * @package Theme Name
 */

get_header(); ?>
<div id="content" class="site-content">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

                <?php while ( have_posts() ) : the_post(); ?>

                        <?php get_template_part( 'content', 'page' ); ?>

                        <?php if ( comments_open() || get_comments_number() ) : ?>
                                <section class="section-gradient">
                                    <div class="container">
                                        comments_template();
                                    </div><!-- .container -->
                                </section>
                        <?php endif; ?>

                <?php endwhile; // end of the loop. ?>
                <?php wp_reset_postdata(); ?>

        <section class="section-gradient">
            <div class="container">
                <div class="row">
                    <?php
                    $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
                    $args = array( 'post_type' => 'portfolio', 'paged' => $paged, 'posts_per_page' => 3 );
                    $loop = new WP_Query( $args );
                    while ( $loop->have_posts() ) : $loop->the_post(); ?>

                        <?php get_template_part( 'content', 'portfolio' ); ?>

                        <?php if ( comments_open() || get_comments_number() ) : ?>
                                <section class="section-gradient">
                                    <div class="container">
                                        comments_template();
                                    </div><!-- .container -->
                                </section>
                        <?php endif; ?>

                    <?php endwhile; // end of the loop. ?>
                    <?php wp_reset_postdata(); ?>
                </div><!-- .row -->
            </div>
        </section>
        <section class="section-lightdark">
            <div class="container">
            <?php
              if ( function_exists('wp_bootstrap_pagination') )
                wp_bootstrap_pagination();
            ?>
            </div>
        </section>
    </main><!-- #main -->
</div><!-- #primary -->

尝试插入if ($loop->have_posts()) :

在此之前,并在结束之前关闭此条件。

暂无
暂无

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

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