2012-02-27 20 views
1

私の悪い英語のために申し訳ありません。 私はWP 3.3.1 & wp-e-commerce.3.8.7.6.2を持っています。製品ページ(wpsc-products_page.phpテンプレートを使用)には、製品のリストがあります。この商品をカテゴリ別にグループ化したいと思います。例えば:wp電子商取引グループカテゴリ別製品

** CAT1
製品1
製品2

** Cat2の
製品1
製品2

** CAT3
製品1
製品2

は、私は、このメソッドを使用しようとするが、それ `sは

add_filter('posts_join', create_function('$a', 'global $wpdb; return $a . " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";')); 
add_filter('posts_where', create_function('$a', 'global $wpdb; return $a . " AND $wpdb->term_taxonomy.taxonomy = \'wpsc_product_category\'";')); 
add_filter('posts_orderby', create_function('$a','global $wpdb; return "$wpdb->term_taxonomy.term_id DESC";')); 
query_posts(''); 

はお返事を事前にすべてのいただきありがとうございます動作しません!

答えて

7

次のコードを試してください。

/* ---------- 
------------- 
Continue code 
------------- 
---------- */ 

<?php 
/* Check if this is the products page not the category or single page */ 
if(is_products_page() && wpsc_is_product() && (!wpsc_is_in_category()) && (!wpsc_is_single_product())) { 
    /* Get all the categories for wp e-commerce products */ 
    $wpec_product_categories = get_terms('wpsc_product_category', 'hide_empty=0&parent=0'); 
    foreach($wpec_product_categories as $wpec_categories){ 
     $wpec_term_id = $wpec_categories->term_id; 
     $wpec_term_name = $wpec_categories->name; 
     $wpec_term_slug = $wpec_categories->slug; 

     //Skip the categories term(which comes default in wp e-commerce 
     if($wpec_term_slug == 'categories') { 
      continue; 
     } 

     //Set the args array 
     $wpec_args = array(
      'post_status' => 'publish', 
      'post_type' => 'wpsc-product', 
      'numberposts' => 12, 
      'showposts' => 12, 
      "wpsc_product_category" => $wpec_term_slug 
     ); 

     $wpec_categoryProducts = new WP_Query($wpec_args); 
    ?> 
     <div class="wpec_productcat_name"><h3><?php echo $wpec_term_name; ?></h3></div> 

    <?php /** start the category wise - products loop here */?> 
    <?php while ($wpec_categoryProducts->have_posts()) : $wpec_categoryProducts->the_post(); 
     global $wpsc_custom_meta, $wpsc_variations; 
     $wpsc_custom_meta = new wpsc_custom_meta(get_the_ID()); 
     $wpsc_variations = new wpsc_variations(get_the_ID()); 
    ?> 
     <div class="default_product_display product_view_<?php echo wpsc_the_product_id(); ?> <?php echo wpsc_category_class(); ?> group"> 

/* ---------- 
------------- 
Continue code - product display 
------------- 
---------- */ 

     </div><!--close default_product_display--> 
    <?php endwhile; ?> 
    <?php /** end the product loop here */?>  

<?php 
} 
else { 
?> 
    <?php /** start the wp e-commerce default product loop here */ ?> 
    <?php while (wpsc_have_products()) : wpsc_the_product(); ?> 
     <div class="default_product_display product_view_<?php echo wpsc_the_product_id(); ?> <?php echo wpsc_category_class(); ?> group"> 

/* ---------- 
------------- 
Continue code - products display(same code as above) 
------------- 
---------- */ 

     </div><!--close default_product_display--> 
    <?php endwhile; ?> 
    <?php /** end the product loop here */?> 

<?php 
} //End of else block for products page checking 
?> 

上記のコードは、WP Eコマースの商品テンプレート内で使用する必要があります。

ステップ:

- wpsc-products_page.phpファイルを開きます。 - コード内の製品ループステートメントを検索します。

<?php /** start the product loop here */?> 
<?php while (wpsc_have_products()) : wpsc_the_product(); ?> 

- 製品のループ終了ステートメントを検索します。

<?php endwhile; ?> 
<?php /** end the product loop here */ ?> 

- 製品のループの間にブロック全体をコピーし、その間にブロック全体をコピーします。 - 次に、これらのコピーされたコードを以下の条件の中に囲みます。 - 製品ページを保存して確認します。

+0

こんにちは、そのコードをAPI(webservice)として使用して、指定されたカテゴリIDの商品を返品する場合はどうすればよいですか?あらかじめThanx。 – Malloc

+0

@malloc:はい、category-idを受け取り、商品を照会し、必要に応じてフォーマットして返すためのループを実行する関数を作成できます。 例: $ term = get_term($ category_id、 'wpsc_product_category'); $ wpec_term_slug = $ term-> slug; $引数=配列( \t 'post_status' => '公開'、 \t 'post_parent' => 0、 \t 'post_type' => 'wpsc-製品'、 \t 'wpsc_product_category' => $ wpec_term_slug \t ); $ products = get_posts($ args); – Subharanjan

0

管理パネルにアクセスして製品をクリックすると、「カテゴリ」が表示され、個々の製品ページと同様に製品のカテゴリが作成されます。次に、製品ページで各製品に移動し、どのカテゴリに適合するかを選択することができます。

設定>店舗>外観検索「商品ページに表示する商品カテゴリを選択:」を選択し、矢印を「商品カテゴリのリストを表示」に移動します。

「ページタイトルを製品/カテゴリ名に置き換えてください」と表示されたら、「はい」をクリックします。

次に、外観>メニューに移動し、メニューをクリックします。下にスクロールすると、作成した商品カテゴリをメニューに追加できることがわかります。私はそれらを私の店にサブアイテムとして入れました。誰かがショップをクリックすると、最初のページが商品カテゴリのリストになります。カテゴリをクリックすると、そのカテゴリの商品のリストが表示されます。

私はこれが達成しようとしていると思います。

私のサイトには、次のとおりです。www.greenhillsoaps.com

は、この情報がお役に立てば幸いです。

関連する問題