本文介绍了WooCommerce中的分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此短代码在页面上显示产品的类别.但是当我们使用它时,它没有显示分页.因为我们的分类中有很多产品.

I am using this shortcode to show products form a category on a page . but when we are using this then it is not showing pagination . because we have so many products in our category .

我们正在使用以下代码:

we are using the following code:

[product_category category="snowpeak" per_page="12" columns="4" orderby="date" order="desc"]

推荐答案

您可以在此处投票支持在WooCommerce简码中实现的此功能: http://ideas.woothemes.com/forums/133476-woocommerce/suggestions/4146798-add-pagination-support-for-list-of-products-render

You can vote for this feature to implemented into the WooCommerce Shortcode here:http://ideas.woothemes.com/forums/133476-woocommerce/suggestions/4146798-add-pagination-support-for-list-of-products-render

否则,您可以创建自定义产品循环( http://docs.woothemes .com/document/sample-products-loop/),并在WP_Query中为分页添加自定义arg:

Otherwise you can create a custom Product Loop (http://docs.woothemes.com/document/sample-products-loop/) and add a custom arg in WP_Query for Pagination:

例如

    <ul class="products">
        <?php
        global $paged;

            $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
            $args = array(
                'post_type' => 'product',
                'posts_per_page' => 4,
                'paged' => $paged


                );
            $loop = new WP_Query( $args );
            if ( $loop->have_posts() ) {
                while ( $loop->have_posts() ) : $loop->the_post();
                    woocommerce_get_template_part( 'content', 'product' );
                endwhile;
            } else {
                echo __( 'No products found' );
            }
        ?>


    <nav>
        <ul>
            <li><?php previous_posts_link( '&laquo; PREV', $loop->max_num_pages) ?></li> 
            <li><?php next_posts_link( 'NEXT &raquo;', $loop->max_num_pages) ?></li>
        </ul>
    </nav>

    <?php wp_reset_postdata(); ?>
    </ul><!--/.products-->

  • 参考:对自定义帖子wp_query的分页
    • reference: pagination on custom post wp_query
    • 这篇关于WooCommerce中的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 04:05