Wordpress wp电子商务集团产品(按类别)
对不起,我的英语不好。 我有WP 3.3.1和WP-e-commerce.3.8.7.6.2。在使用wpsc-products_page.php模板的产品页面上,我有产品列表。我想按类别对这些产品进行分组。例如: **第一类 产品1 产品2 **第二类 产品1 产品2 **第三类 产品1 产品2 我试着用这个方法,但它不起作用Wordpress wp电子商务集团产品(按类别),wordpress,e-commerce,sql-order-by,categories,product,Wordpress,E Commerce,Sql Order By,Categories,Product,对不起,我的英语不好。 我有WP 3.3.1和WP-e-commerce.3.8.7.6.2。在使用wpsc-products_page.php模板的产品页面上,我有产品列表。我想按类别对这些产品进行分组。例如: **第一类 产品1 产品2 **第二类 产品1 产品2 **第三类 产品1 产品2 我试着用这个方法,但它不起作用 add_filter('posts_join', create_function('$a', 'global $wpdb; return $a . " INNER JOI
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('');
提前感谢大家的回复 如果您转到管理面板并单击产品,您将看到类别单击该面板并为您的产品创建类别,就像单个产品页面一样。然后在产品页面中,转到每个产品,您可以选择适合它们的类别 在“设置”>“门店”>“外观查找”中,选择要在“产品”页面上显示的产品类别:并移动箭头以显示产品类别列表 然后找到“用产品/类别名称替换页面标题”:单击“是” 然后进入外观>菜单并单击菜单。如果向下滚动,您将看到您创建的产品类别可以添加到菜单中。我已将它们作为子项放入我的店铺。当有人点击商店时,第一页是产品类别列表。如果他们点击一个类别,他们会得到该类别的产品列表 我想这就是你想要达到的目标 我的网站是:www.greenhillsoaps.com
希望这对您有所帮助。如果您转到“管理”面板并单击“产品”,您将看到类别单击该面板并为您的产品创建类别,就像单个产品页面一样。然后在产品页面中,转到每个产品,您可以选择适合它们的类别 在“设置”>“门店”>“外观查找”中,选择要在“产品”页面上显示的产品类别:并移动箭头以显示产品类别列表 然后找到“用产品/类别名称替换页面标题”:单击“是” 然后进入外观>菜单并单击菜单。如果向下滚动,您将看到您创建的产品类别可以添加到菜单中。我已将它们作为子项放入我的店铺。当有人点击商店时,第一页是产品类别列表。如果他们点击一个类别,他们会得到该类别的产品列表 我想这就是你想要达到的目标 我的网站是:www.greenhillsoaps.com 希望这有帮助。尝试下面的代码
/* ----------
-------------
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文件。
–在代码中找到products循环语句
<?php /** start the product loop here */?>
<?php while (wpsc_have_products()) : wpsc_the_product(); ?>
–查找产品循环结束语句
<?php endwhile; ?>
<?php /** end the product loop here */ ?>
–为产品循环复制while和endwhile之间的整个块。
–然后将复制的代码封装在下面提到的条件中。
–保存并检查产品页面。尝试以下代码
/* ----------
-------------
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文件。
–在代码中找到products循环语句
<?php /** start the product loop here */?>
<?php while (wpsc_have_products()) : wpsc_the_product(); ?>
–查找产品循环结束语句
<?php endwhile; ?>
<?php /** end the product loop here */ ?>
–为产品循环复制while和endwhile之间的整个块。
–然后将复制的代码封装在下面提到的条件中。
–保存并检查产品页面。您好,如果我想将该代码用作API Web服务以返回给定类别ID的产品,该怎么办?Thanx提前。@malloc:是的,您可以创建一个函数,该函数接受类别id,然后查询产品,运行一个循环以根据您的需要对其进行格式化并返回。示例:$term=get_term$category_id,'wpsc_product_category'$wpec_term_slug=$term->slug$args=array'post_status'=>'publish'、'post_parent'=>0、'post_type'=>'wpsc product'、'wpsc_product_category'=>$wpec_term_slug$products=get_posts$args;您好,如果我想将该代码用作API Web服务来返回给定类别ID的产品,该怎么办?Thanx提前。@malloc:是的,您可以创建一个函数,该函数接受类别id,然后查询产品,运行一个循环以根据您的需要对其进行格式化并返回。示例:$term=get_term$category_id,'wpsc_product_category'$wpec_term_slug=$term->slug$args=array'post_status'=>'publish'、'post_parent'=>0、'post_type'=>'wpsc product'、'wpsc_product_category'=>$wpec_term_slug$products=get_posts$args;