示例#1
0
function show_products_outside_loop($atts)
{
    global $shortcode_query, $product_sort, $archive_template, $shortcode_args;
    $available_args = apply_filters('show_products_shortcode_args', array('post_type' => 'al_product', 'category' => '', 'product' => '', 'exclude' => '', 'products_limit' => -1, 'archive_template' => get_product_listing_template(), 'design_scheme' => '', 'sort' => 0, 'orderby' => '', 'order' => ''));
    $args = shortcode_atts($available_args, $atts);
    $shortcode_args = $args;
    $category = esc_html($args['category']);
    $product = esc_html($args['product']);
    $exclude = esc_html($args['exclude']);
    $products_limit = intval($args['products_limit']);
    $archive_template = esc_attr($args['archive_template']);
    $design_scheme = esc_attr($args['design_scheme']);
    $product_sort = intval($args['sort']);
    if ($product != 0) {
        $product_array = explode(',', $product);
        $query_param = array('post_type' => 'al_product', 'post__in' => $product_array, 'posts_per_page' => $products_limit);
    } else {
        if (!empty($category)) {
            $category_array = explode(',', $category);
            $field = 'name';
            if (is_numeric($category_array[0])) {
                $field = 'term_id';
            }
            $query_param = array('post_type' => 'al_product', 'tax_query' => array(array('taxonomy' => 'al_product-cat', 'field' => $field, 'terms' => $category_array)), 'posts_per_page' => $products_limit);
        } else {
            $query_param = array('post_type' => 'al_product', 'posts_per_page' => $products_limit);
            if (!empty($exclude)) {
                $query_param['post__not_in'] = explode(',', $exclude);
            }
        }
    }
    if (!empty($args['orderby'])) {
        $query_param['orderby'] = esc_attr($args['orderby']);
    }
    if (!empty($args['order'])) {
        $query_param['order'] = esc_attr($args['order']);
    }
    $query_param = apply_filters('shortcode_query', $query_param, $args);
    $shortcode_query = new WP_Query($query_param);
    $inside = '';
    $i = 0;
    ob_start();
    do_action('before_product_list', $archive_template);
    $before = ob_get_contents();
    ob_end_clean();
    while ($shortcode_query->have_posts()) {
        $shortcode_query->the_post();
        global $post;
        $i++;
        $inside .= get_catalog_template($archive_template, $post, $i, $design_scheme);
    }
    $inside = apply_filters('product_list_ready', $inside, $archive_template, $args);
    wp_reset_postdata();
    reset_row_class();
    unset($shortcode_args);
    return $before . '<div class="product-list responsive ' . $archive_template . ' ' . product_list_class($archive_template) . '">' . $inside . '<div style="clear:both"></div></div>';
}
示例#2
0
/**
 * Shows products on product listing for custom templates usage
 *
 * @return type
 */
function ic_product_listing_products()
{
    ob_start();
    global $post;
    $multiple_settings = get_multiple_settings();
    $archive_template = get_product_listing_template();
    if (is_home_archive()) {
        $args = array('post_type' => 'al_product', 'posts_per_page' => $multiple_settings['archive_products_limit']);
        query_posts($args);
        $is_home = 1;
    }
    if ((is_tax() || is_search() || !is_ic_only_main_cats()) && more_products()) {
        do_action('before_product_list', $archive_template, $multiple_settings);
        $product_list = '';
        while (have_posts()) {
            the_post();
            $product_list .= get_catalog_template($archive_template, $post);
        }
        if (isset($is_home)) {
            wp_reset_query();
        }
        $product_list = apply_filters('product_list_ready', $product_list, $archive_template, 'auto_listing');
        echo '<div class="product-list responsive ' . $archive_template . ' ' . product_list_class($archive_template) . '">' . $product_list . '</div><span class="clear"></span>';
    } else {
        if (is_search() && !more_products()) {
            echo '<p>' . __('Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'ecommerce-product-catalog') . '</p>';
            product_search_form();
        }
    }
    return ob_get_clean();
}
function show_products_outside_loop($atts)
{
    global $shortcode_query, $product_sort;
    $args = shortcode_atts(array('post_type' => 'al_product', 'category' => '', 'product' => '', 'products_limit' => -1, 'archive_template' => get_option('archive_template', 'default'), 'design_scheme' => '', 'sort' => 0), $atts);
    $sort = (int) $args['sort'];
    $category = esc_attr($args['category']);
    $product = esc_attr($args['product']);
    $products_limit = (int) $args['products_limit'];
    $archive_template = esc_attr($args['archive_template']);
    $design_scheme = esc_attr($args['design_scheme']);
    //	$post_type = esc_attr($args['post_type']);
    $product_sort = $sort;
    if ($product != 0) {
        $product_array = explode(',', $product);
        $query_param = array('post_type' => 'al_product', 'post__in' => $product_array, 'posts_per_page' => $products_limit);
    } else {
        if ($category != 0) {
            $category_array = explode(',', $category);
            $query_param = array('post_type' => 'al_product', 'tax_query' => array(array('taxonomy' => 'al_product-cat', 'field' => 'term_id', 'terms' => $category_array)), 'posts_per_page' => $products_limit);
        } else {
            $query_param = array('post_type' => 'al_product', 'posts_per_page' => $products_limit);
        }
    }
    $query_param = apply_filters('shortcode_query', $query_param);
    $shortcode_query = new WP_Query($query_param);
    $inside = '';
    $i = 0;
    do_action('before_product_list', $archive_template);
    while ($shortcode_query->have_posts()) {
        $shortcode_query->the_post();
        global $post;
        $i++;
        $inside .= get_catalog_template($archive_template, $post, $i, $design_scheme);
    }
    $inside = apply_filters('product_list_ready', $inside, $archive_template);
    wp_reset_postdata();
    return '<div class="product-list responsive ' . $archive_template . '-list ' . product_list_class() . '">' . $inside . '<div style="clear:both"></div></div>';
}
                if ($archive_template != 'list') {
                    echo '<hr>';
                }
            }
        }
    }
}
do_action('before_product_list', $archive_template, $multiple_settings);
$product_list = '<div class="product-list responsive ' . product_list_class() . '">';
if (is_home_archive()) {
    $args = array('post_type' => 'al_product');
    query_posts($args);
    $is_home = 1;
}
while (have_posts()) {
    the_post();
    $product_list .= get_catalog_template($archive_template, $post);
}
if (isset($is_home)) {
    wp_reset_query();
}
$product_list .= '</div>';
$product_list = apply_filters('product_list_ready', $product_list, $archive_template);
echo $product_list;
?>
<span class="clear"></span>
	</div>

</article>
<?php 
product_archive_pagination();
/**
 * Generates product listing products
 *
 * @param type $archive_template
 * @param type $multiple_settings
 */
function ic_product_listing_products($archive_template, $multiple_settings)
{
    global $post, $ic_is_home;
    if (is_home_archive() || !more_products() && is_custom_product_listing_page()) {
        if (get_query_var('paged')) {
            $paged = get_query_var('paged');
        } elseif (get_query_var('page')) {
            $paged = get_query_var('page');
        } else {
            $paged = 1;
        }
        $args = apply_filters('home_product_listing_query', array('post_type' => 'al_product', 'posts_per_page' => $multiple_settings['archive_products_limit'], 'paged' => $paged));
        query_posts($args);
        $ic_is_home = 1;
    }
    if ((is_tax() || is_search() || !is_ic_only_main_cats() || is_product_filters_active()) && more_products()) {
        do_action('before_product_list', $archive_template, $multiple_settings);
        $product_list = '';
        while (have_posts()) {
            the_post();
            $product_list .= get_catalog_template($archive_template, $post);
        }
        $product_list = apply_filters('product_list_ready', $product_list, $archive_template, 'auto_listing');
        echo '<div class="product-list responsive ' . $archive_template . ' ' . product_list_class($archive_template) . '">' . $product_list . '</div><span class="clear"></span>';
    } else {
        if (!is_product_filters_active() && is_search() && !more_products()) {
            echo '<p>' . __('Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'ecommerce-product-catalog') . '</p>';
            product_search_form();
        } else {
            if (is_product_filters_active() && !more_products()) {
                show_product_sort_bar();
                $filters = get_active_product_filters();
                if (isset($_GET['s'])) {
                    $filters[] = 's';
                }
                echo '<p>' . sprintf(__('Sorry, but nothing matched your search terms. Please try again with some different options or %sreset filters%s.', 'ecommerce-product-catalog'), '<a href="' . esc_url(remove_query_arg($filters)) . '">', '</a>') . '</p>';
            }
        }
    }
}