簡體   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