对不起,我的英语不好。我有WP 3.3.1 & wp-e-commerce.3.8.7.6.2。在products页面(使用wpsc- products _page.php模板)上,我有一个产品列表。我想把这些产品按类别分组。例如:
**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('');提前感谢大家的回复!
发布于 2012-03-11 22:26:25
尝试下面的代码。
/* ----------
-------------
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(); ?>-查找products循环结束语句。
<?php endwhile; ?>
<?php /** end the product loop here */ ?>-对于产品循环,在while和endwhile之间复制整个块。-然后将这些复制的代码包含在下面提到的条件中。-保存并检查产品页面。
发布于 2012-03-09 00:36:04
如果您转到管理面板并单击产品,您将看到“类别”单击它并为您的产品创建类别,就像单个产品页面一样。然后在您的产品页面中,转到每个产品,您可以选择它们适合的类别。
在settings>store>appearance中,找到“选择要在产品页面上显示的产品类别:”,然后将箭头移动到“显示产品类别列表”。
然后找到"Replace Page Title With Product/Category Name:“,单击yes。
然后转到appearance>menu并单击菜单。如果向下滚动,您将看到您创建的产品类别可以添加到您的菜单中。我已经把它们作为子项放到我的店里了。当有人点击商店时,第一个页面是产品类别列表。如果他们点击一个类别,他们就会得到该类别的产品列表。
我想这就是你想要实现的。
我的网站是: www.greenhillsoaps.com
希望这能有所帮助。
https://stackoverflow.com/questions/9462765
复制相似问题