简体   繁体   English

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

[英]pagination custom post type with multiple WP_Query loop

after adding the function of pagination to Functions.php and recall it in template-product-listing.php there is nothing shown in result. 将分页功能添加到Functions.php并在template-product-listing.php中调用它后,结果中没有任何显示。 I have a big problom with this... 我对此有个大问题...

could you find and resolve the problem? 您能找到并解决问题吗?

thnx n

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

if your sure there is a post_type called products and there is posts in it... 如果您确定有一个名为product的post_type并且其中有帖子...

try: 尝试:

 <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(); ?>

You know you are starting a new wp_query for every post in have_posts() ? 您知道您要为have_posts()中的每个帖子启动一个新的wp_query吗? you might want to rethink what you are trying to achieve! 您可能想重新考虑您要实现的目标!

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

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