/** * Output pagination for the current loop. * * @since 4.9 * @uses wpsc_is_pagination_enabled() * @uses wpsc_get_template_part() * * @param string $position Position of the pagination div. */ function wpsc_product_pagination($position = 'bottom') { if (!wpsc_is_pagination_enabled($position)) { return; } echo '<div class="wpsc-pagination wpsc-pagination-' . esc_attr($position) . '">'; wpsc_get_template_part('product-pagination', $position); echo '</div>'; }
/** * Products shortcode * * Usage example: * - [wpsc-products id="12"] * - [wpsc-products id="12, 15"] * - [wpsc-products display="sale"] * * Available attributes: * * - 'id': A single, or a comma separated list of product IDs. Set to '0' will * display all products matching remaining criteria. Defaults to '0'. * - 'display': Defaults to 'all' * + display="all" will display all products * + display="sale" will only display products on sale * + display="not-sale" will only display products not on sale * - 'per_page': Set to -1 to disable pagination. Defaults to -1. * - 'paged': Current page number * - 'offset': Skip how many products at the beginning of the found results * - 'template_part': Which template part to include to display this shortcode. * Defaults to 'loop-products' * - 'category_in': Comma separated list of categories whose products you want to display * - 'category_not_in': Comma separated list of categories you want to exclude * - 'tag_in': Comma separated list of tags whose products you want to display * - 'tag_not_in': Comma separated list of tags whose products you want to exclude * * @param array $atts Attributes * @return string Shortcode output */ function _wpsc_shortcode_products($atts) { // Default and allowed attributes $defaults = array('id' => 0, 'display' => 'all', 'per_page' => -1, 'paged' => 1, 'offset' => 0, 'template_part' => 'loop-products', 'category_in' => '', 'category_not_in' => '', 'tag_in' => '', 'tag_not_in' => ''); $args = array('post_type' => 'wpsc-product'); $atts = shortcode_atts($defaults, $atts, 'wpsc-products'); // Query by post ID $atts['id'] = str_replace(' ', '', $atts['id']); $ids = empty($atts['id']) ? array() : array_map('absint', explode(',', $atts['id'])); if (!empty($ids)) { $args['post__in'] = $ids; } // Meta query for whether to select products on sale or not switch ($atts['display']) { case 'sale': $args['meta_query'] = array(array('key' => '_wpsc_special_price', 'value' => array('', '0'), 'compare' => 'NOT IN')); break; case 'not-sale': $args['meta_query'] = array(array('key' => '_wpsc_special_price', 'value' => array('', '0'), 'compare' => 'IN')); break; } // Pagination if ($atts['per_page'] !== -1) { $args['posts_per_page'] = absint($atts['per_page']); $args['paged'] = absint($atts['paged']); $args['offset'] = absint($atts['offset']); } else { $args['nopaging'] = true; } // Taxonomy queries $atts['category_in'] = str_replace(' ', '', $atts['category_in']); $atts['category_not_in'] = str_replace(' ', '', $atts['category_not_in']); $atts['tag_in'] = str_replace(' ', '', $atts['tag_in']); $atts['tag_not_in'] = str_replace(' ', '', $atts['tag_not_in']); $atts['category_in'] = empty($atts['category_in']) ? array() : array_map('absint', explode(',', $atts['category_in'])); $atts['category_not_in'] = empty($atts['category_not_in']) ? array() : array_map('absint', explode(',', $atts['category_not_in'])); $atts['tag_in'] = empty($atts['tag_in']) ? array() : array_map('absint', explode(',', $atts['tag_in'])); $atts['tag_not_in'] = empty($atts['tag_not_in']) ? array() : array_map('absint', explode(',', $atts['tag_not_in'])); $args['tax_query'] = array(); // Category slug in if (!empty($atts['category_in'])) { $args['tax_query'][] = array('taxonomy' => 'wpsc_product_category', 'field' => 'slug', 'terms' => $atts['category_in'], 'operator' => 'IN'); } // Category slug not in if (!empty($atts['category_not_in'])) { $args['tax_query'][] = array('taxonomy' => 'wpsc_product_category', 'field' => 'slug', 'terms' => $atts['category_not_in'], 'operator' => 'NOT IN'); } // Product tag in if (!empty($atts['tag_in'])) { $args['tax_query'][] = array('taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $atts['tag_in'], 'operator' => 'IN'); } // Product tag not in if (!empty($atts['tag_not_in'])) { $args['tax_query'][] = array('taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $atts['tag_not_in'], 'operator' => 'NOT IN'); } // I don't like query posts either but we need to preserve the ability // to use the_post() from within the templates, without having to resort // to tags like $query->the_post() query_posts($args); ob_start(); wpsc_get_template_part($atts['template_part']); $output = ob_get_clean(); wp_reset_query(); return $output; }
<?php /** * The template part for displaying the product loop. * * Override this template by copying it to theme-folder/wp-e-commerce/loop-products.php * * @author WP eCommerce * @package WP-e-Commerce/Templates * @version 4.0 */ ?> <section id="wpsc-products"> <?php while (wpsc_have_products()) { wpsc_the_product(); ?> <?php wpsc_get_template_part('product', 'excerpt'); ?> <?php } ?> </section>
* * Override this template by copying it to theme-folder/wp-e-commerce/category.php * * @author WP eCommerce * @package WP-e-Commerce/Templates * @version 4.0 */ if (wpsc_have_products()) { ?> <?php wpsc_breadcrumb(); ?> <?php wpsc_category_filter(); ?> <?php wpsc_product_pagination('top'); ?> <?php wpsc_get_template_part('loop', 'products'); ?> <?php wpsc_product_pagination('bottom'); } else { ?> <?php wpsc_category_filter(); ?> <?php wpsc_get_template_part('feedback', 'no-products'); }
public function get_replaced_content() { global $wp_query; $current_controller = _wpsc_get_current_controller_name(); $before = apply_filters('wpsc_replace_the_content_before', '<div class="%s">', $current_controller); $after = apply_filters('wpsc_replace_the_content_after', '</div>', $current_controller); $before = sprintf($before, 'wpsc-page wpsc-page-' . $current_controller); ob_start(); wpsc_get_template_part($this->view); $content = ob_get_clean(); return $before . $content . $after; }
function wpsc_customizer_render_products() { wpsc_get_template_part('loop', 'products'); }