dqluw20882 2015-08-05 22:28
浏览 15
已采纳

too long

I have the following category within a site: http://rivetnuttool.com/site/product-category/blue-pneumatic-rivet-nut-tools/ And I want it to show all of the 7 products within the first page, and even if I have 100 products to show them in one single page. I have tried with different solutions like adding this to my functions.php file: add_filter( 'loop_shop_per_page', create_function( '$cols', 'return -1;' ) );

Rewriting the shortcode like the solution proposed here http://ideas.woothemes.com/forums/133476-woocommerce/suggestions/4146798-add-pagination-support-for-list-of-products-render

And several other online options, and none of them seems to work, I allways get the pagination and the limit.

The theme used in the site is Divi.

  • 写回答

4条回答 默认 最新

  • duanjiebian6712 2015-08-06 00:42
    关注

    I corrected and changed the custom code from the above blog post to:

    function shortcode_settori( $atts ) {
                global $woocommerce_loop;
    
                extract( shortcode_atts( array(
                        'per_page' => '24',
                        'columns' => '4',
                        'orderby' => 'title',
                        'order' => 'desc',
                        'settore' => '', // Slugs
                        'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
                ), $atts ) );
                if ( ! $settore ) {
                        return '';
                }
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                // Default ordering args
                $ordering_args = WC()->query->get_catalog_ordering_args( $orderby, $order );
    
                $args = array(
            'post_type'             => 'product',
            'post_status'           => 'publish',
            'ignore_sticky_posts'   => 1,
            'posts_per_page'        => '999',
            'meta_query'            => array(
                array(
                    'key'           => '_visibility',
                    'value'         => array('catalog', 'visible'),
                    'compare'       => 'IN'
                )
            ),
            'tax_query'             => array(
                array(
                    'taxonomy'      => 'product_cat',
                    'field' => 'term_id', //This is optional, as it defaults to 'term_id'
                    'terms'         => $settore,
                    'operator'      => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
                )
            )
                );
                $products = new WP_Query($args);
    
                $woocommerce_loop['columns'] = $columns;
                if ( $products->have_posts() ) : ?>
                        <?php woocommerce_product_loop_start(); ?>
                        <?php while ( $products->have_posts() ) : $products->the_post(); ?>
                                <?php wc_get_template_part( 'content', 'product' ); ?>
                        <?php endwhile; // end of the loop. ?>
                        <?php woocommerce_product_loop_end(); ?>
    
                <?php endif;
                if($products->max_num_pages>1){
                ?>
                <nav class="woocommerce-pagination">
                    <?php
                    echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
                        'base' => esc_url( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) ),
                        'format' => '',
                        'current' => max( 1, get_query_var( 'paged' ) ),
                        'total' => $products->max_num_pages,
                        'prev_text' => '&larr;',
                        'next_text' => '&rarr;',
                        'type' => 'list',
                        'end_size' => 3,
                        'mid_size' => 3
                        ) ) );
                        ?>
                </nav>
    
        <?php }
        woocommerce_reset_loop();
        wp_reset_postdata();
        echo $return;
        $return = '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
        // Remove ordering query arguments
        WC()->query->remove_ordering_args();
    
        return $return;
    }
    
    add_shortcode( 'prodotti_per_settore', 'shortcode_settori' );
    

    And everything works now.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误