コード例 #1
0
ファイル: shortcodes.php プロジェクト: bergvogel/stayuplate
 function snpshpwp_product_categories($atts, $content = null)
 {
     extract(shortcode_atts(array('ids' => '', 'per_page' => 4, 'columns' => '4', 'orderby' => 'date', 'order' => 'DESC', 'bot_margin' => 36, 'hide_empty' => 1, 'parent' => '', 'class' => '', 'shortcode_id' => '', 'animate' => 'none', 'animation_delay' => 0, 'animation_group' => ''), $atts));
     if ($ids == '') {
         return __('Please select categories', 'snpshpwp');
     }
     $bot_margin = (int) $bot_margin;
     $margin = ' style="margin-bottom:' . $bot_margin . 'px"';
     $out = '';
     global $woocommerce_loop;
     if (isset($atts['ids'])) {
         $ids = explode(',', $atts['ids']);
         $ids = array_map('trim', $ids);
     } else {
         $ids = array();
     }
     $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0;
     $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => 1, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent, 'parent' => '');
     $product_categories = get_terms('product_cat', $args);
     $cat_num = count($product_categories);
     $product_categories = array_slice($product_categories, 0, $rows * $columns);
     $pagination = snpshpwp_mini_woo_pagination_cat($cat_num, 1, $rows * $columns, 'yes');
     if ($parent !== "") {
         $product_categories = wp_list_filter($product_categories, array('parent' => $parent));
     }
     if ($hide_empty) {
         foreach ($product_categories as $key => $category) {
             if ($category->count == 0) {
                 unset($product_categories[$key]);
             }
         }
     }
     $woocommerce_loop['columns'] = $columns;
     ob_start();
     $woocommerce_loop['loop'] = $woocommerce_loop['column'] = '';
     if ($product_categories) {
         woocommerce_product_loop_start();
         foreach ($product_categories as $category) {
             wc_get_template('content-product_cat.php', array('category' => $category));
         }
         woocommerce_product_loop_end();
     }
     woocommerce_reset_loop();
     $shortcode = ob_get_clean();
     $out .= '<div class="snpshpwp_woo_wrap div_touch_optimized snpshpwp_div_inherit_width"' . $margin . ' data-shortcode="' . $bot_margin . '|' . $columns . '|' . $per_page . '|' . $order . '|' . $orderby . '|' . implode(',', $ids) . '">' . do_shortcode($shortcode) . $pagination . '</div>';
     return $out;
 }
コード例 #2
0
ファイル: functions.php プロジェクト: bergvogel/stayuplate
 function snpshpwp_ajaxload_send_woo_cat()
 {
     global $woocommerce, $woocommerce_loop;
     $current_page = $_POST['page'];
     $page = $_POST['page'];
     $ajax = $_POST['ajax'];
     $bot_margin = $_POST['bot_margin'];
     $columns = $_POST['columns'];
     $per_page = $_POST['per_page'];
     $order = $_POST['order'];
     $orderby = $_POST['orderby'];
     $ids = $_POST['ids'];
     $hide_empty = 1;
     $parent = '';
     $ids = explode(',', $ids);
     $ids = array_map('trim', $ids);
     $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => 1, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent, 'parent' => '', 'offset' => $per_page * ($page - 1));
     $product_categories = get_terms('product_cat', $args);
     $cat_num = count($product_categories);
     $product_categories = array_slice($product_categories, $per_page * ($page - 1), $per_page);
     $pagination = snpshpwp_mini_woo_pagination_cat($cat_num, $current_page, $per_page, 'yes');
     if ($parent !== "") {
         $product_categories = wp_list_filter($product_categories, array('parent' => $parent));
     }
     if ($hide_empty) {
         foreach ($product_categories as $key => $category) {
             if ($category->count == 0) {
                 unset($product_categories[$key]);
             }
         }
     }
     $woocommerce_loop['columns'] = $columns;
     ob_start();
     // Reset loop/columns globals when starting a new loop
     $woocommerce_loop['loop'] = $woocommerce_loop['column'] = '';
     if ($product_categories) {
         woocommerce_product_loop_start();
         foreach ($product_categories as $category) {
             wc_get_template('content-product_cat.php', array('category' => $category));
         }
         woocommerce_product_loop_end();
     }
     woocommerce_reset_loop();
     $shortcode = ob_get_clean();
     die('<div class="woocommerce">' . $shortcode . '</div>' . snpshpwp_mini_woo_pagination_cat($cat_num, $page, $per_page, 'yes'));
 }