2012-02-27 3 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 : 예를 들어,

나는이 방법을 사용하려고하지만, 그것은`

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 전자 상거래의 제품 템플릿 내에서 사용해야합니다.

단계 :

- 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 */ ?> 

- 제품 루프 동안 전체 블록을 while과 endwhile 사이에 복사하십시오. - 그런 다음 복사 된 코드를 아래에 언급 된 조건으로 묶으십시오. - 저장하고 제품 페이지를 확인하십시오.

+0

안녕하세요, 해당 코드를 API (webservice)로 사용하여 주어진 카테고리 ID의 제품을 반환하려면 어떻게해야합니까? 고맙습니다. – 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

관리자 패널로 이동하여 제품을 클릭하면 "카테고리"가 클릭되어 개별 제품 페이지처럼 제품 카테고리가 생성됩니다. 그런 다음 제품 페이지에서 각 제품으로 이동하여 해당 카테고리를 선택할 수 있습니다.

설정> store> appearance에서 "제품 페이지에 표시 할 제품 카테고리 선택 :"을 선택하고 화살표를 "제품 카테고리 목록 표시"로 이동하십시오.

"페이지 제목을 제품/카테고리 이름으로 바꿉니다 :"를 찾으십시오. 예를 클릭하십시오.

그런 다음 모양> 메뉴로 이동하여 메뉴를 클릭하십시오. 아래로 스크롤하면 생성 한 제품 카테고리를 메뉴에 추가 할 수 있습니다. 나는 그것을 하위 항목으로 내 가게에 넣었다. 누군가가 상점을 클릭하면 첫 번째 페이지가 제품 카테고리 목록이됩니다. 카테고리를 클릭하면 해당 카테고리의 제품 목록이 표시됩니다.

나는 이것이 당신이 성취하려고 시도하는 것이라고 생각합니다.

내 사이트는 다음과 같습니다 www.greenhillsoaps.com이 도움이

희망.

관련 문제