如何使用Shopp列出所有产品

时间:2012-06-20 12:16:08

标签: php e-commerce shopp

尝试使用适用于Wordpress的Shopp插件获取所有产品的列表。我错过了什么?我可以获得类别列表以及每个类别中的所有产品,但不会出现未分类的产品。

这就是我所拥有的:

<?php
    $cats = shopp_product_categories();
    $dropdown = array();
    foreach ( $cats as $cat ) :
        $dropdown[$cat->slug]['group_name'] = $cat->name;
        $dropdown[$cat->slug]['group_items'] = shopp_category_products( $cat->id );
    endforeach;
?>

我还想添加$ dropdown ['uncategorized'] ['group_items']和一系列未分类的项目。

提前致谢!

2 个答案:

答案 0 :(得分:5)

这个简单的解决方案对我很有用:

<?php shopp('storefront','catalog-products','load=true&show=999'); if ( shopp('collection','has-products') ) { while ( shopp('collection','products') ) { ?><a href="<?php shopp('product','url'); ?>"><?php shopp('product','name'); ?></a><?php } } ?>

答案 1 :(得分:2)

我明白了。 :)

最终看起来像这样:

$cats = shopp_product_categories();
$cat_ids = array();
$dropdown = array();
foreach ( $cats as $cat ) :
    $cat_ids[] = $cat->id;
    $dropdown[$cat->slug]['group_name'] = $cat->name;
    $dropdown[$cat->slug]['group_items'] = shopp_category_products( $cat->id );
endforeach;

$products = new WP_Query( array(
    'post_type' => 'shopp_product',
    'posts_per_page' => -1,
    'tax_query' => array(
        array(
            'taxonomy' => 'shopp_category',
            'field' => 'id',
            'terms' => $cat_ids,
            'operator' => 'NOT IN'
        )
    )

) );

$dropdown['uncategorized']['group_name'] = 'Uncategorized';
while ( $products->have_posts() ) : $products->the_post();
    $dropdown['uncategorized']['group_items'][] = array(
        'id' => get_the_ID(),
        'name' => get_the_title()
    );
endwhile;