具有多个WP_Query循环的分页自定义帖子类型

时间:2014-07-28 21:01:06

标签: php wordpress pagination wp-query

Functions.php 中添加分页功能后,在 template-product-listing.php 中调用它 结果中没有显示任何内容。 我有一个很大的问题......

你能找到并解决问题吗?

日Thnx

        <article class="row">

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

            <div id="single-head" class="sixteen columns">
                <h1><?php the_title(); ?></h1>
                <?php if (has_excerpt()) { the_excerpt(); } ?>
            </div>

            <div class="row">
                <nav id="portfolio-filters" class="sixteen columns">
                    <a href="#filter" class="active-item" data-filter="*"><?php _e('Show All', 'ci_theme'); ?></a>
                    <?php
                    $args = array(
                        'hide_empty' => 0
                    );

                    $skills = get_terms('product-category', $args);
                    ?>
                    <?php foreach ( $skills as $skill ) : ?>
                        <a href="#filter" data-filter=".<?php echo $skill->slug; ?>"><?php echo $skill->name; ?></a>
                    <?php endforeach; ?>
                </nav><!-- /portfolio-filters -->
            </div>

            <div id="portfolio-items" class="row">
                <?php $ci_product_query = new WP_Query('post_type=product&posts_per_page=4'); ?>
                <?php if ( $ci_product_query-> have_posts() ) : while ( $ci_product_query->have_posts() ) : $ci_product_query->the_post(); ?>
                <?php $item_skills = wp_get_object_terms($post->ID, 'product-category');    ?>

                <article class="<?php ci_e_setting('product_columns'); ?> columns <?php foreach ( $item_skills as $item_skill ) : echo $item_skill->slug.' '; endforeach; ?> columns portfolio-item">

                    <a href="<?php echo get_permalink(); ?>" title="<?php echo esc_attr(get_the_title()); ?>" class="fb">
                        <?php the_post_thumbnail('ci_portfolio_slider', array('class'=>'scale-with-grid')); ?>
                    </a>
                    <div class="portfolio-desc">
                        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                        <p class="desc"><?php echo mb_substr(get_the_excerpt(), 0, 70); ?>...</p>
                    </div>
                </article><!-- /portfolio-item -->

                <?php endwhile; endif; ?>
                <?php wp_reset_postdata(); ?>

            </div><!-- /portfolio-items -->

            <?php get_template_part('part', 'call_to_action'); ?>

            <?php endwhile; endif; ?>
        <div class="pagination">
        <?php wp_pagination(); ?>
        </div>
        </article>

1 个答案:

答案 0 :(得分:0)

如果你确定有一个名为产品的post_type并且其中有帖子......

尝试:

 <div id="portfolio-items" class="row">
            <?php $ci_product_query = new WP_Query(array('post_type'=>'product', 'posts_per_page'=> 4); ?>
            <?php if ( $ci_product_query-> have_posts() ) : while ( $ci_product_query->have_posts() ) : $ci_product_query->the_post(); ?>

你知道你正在为have_posts()中的每个帖子开始一个新的wp_query吗?你可能想重新思考你想要实现的目标!