【问题标题】:Wordpress Pagination on Custom Page not working自定义页面上的 Wordpress 分页不起作用
【发布时间】:2015-03-20 04:14:21
【问题描述】:

我在标准循环/查询中创建了一个自定义帖子类型页面 (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 -->

【问题讨论】:

    标签: wordpress twitter-bootstrap pagination


    【解决方案1】:

    尝试插入if ($loop-&gt;have_posts()) :

    while 之前,并在 endwhile 之前关闭此条件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-19
      • 2014-01-25
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多