0

只是尝试使用适用于 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'] 。

提前致谢!

4

2 回答 2

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 } } ?>
于 2012-08-23T21:16:29.457 回答
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;
于 2012-06-20T13:31:48.407 回答