wp电子商务集团产品分类。

时间:2022-02-07 07:33:31

Sorry for my bad english. I have WP 3.3.1 & wp-e-commerce.3.8.7.6.2. On the products page (which use wpsc-products_page.php template) I have list of products. I want to group this products by category. For example:

对不起,我的英语不好。我有WP 3.3.1和WP -e-commerce.3.8.7.6.2。在产品页面上(使用wpsc-products_page)。我有产品列表。我想把这类产品按类别分类。例如:

**Cat1
Product 1
Product 2

**Cat1产品1产品2。

** Cat2
Product 1
Product 2

** Cat2产品1

** Cat3
Product 1
Product 2

** Cat3产品1产品2。

I try to use this method, but it`s does not work

我试着用这个方法,但它不起作用。

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('');

Thank you all in advance for your reply!

感谢您的回复!

2 个解决方案

#1


7  

Try the below code.

尝试以下代码。

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

The above code you have to use inside the product template of WP E-Commerce.

以上代码必须在WP电子商务的产品模板内使用。

Steps:

步骤:

– Open the wpsc-products_page.php file. – Find the products loop statement in the code.

——打开wpsc-products_page。php文件。-在代码中找到产品循环语句。

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

– Find the products loop end statement.

-查找产品循环语句。

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

– Copy the whole block in between while and endwhile for the product loop. – Then enclose those copied code inside the below mentioned condition. – Save and check the products page.

-在产品循环期间,将整个块复制到中间。-然后将复制的代码放在下面的条件下。-保存并检查产品页面。

#2


0  

If you go to the admin panel and click on products, you will see "categories" click on that and create the categories for your products, just like individual product pages. Then in your products page, go to each product and you can select which categories they fit into.

如果你去管理面板点击产品,你会看到“类别”点击,并为你的产品创建类别,就像单独的产品页面一样。然后在你的产品页面,去每个产品,你可以选择他们适合的类别。

In settings>store>appearance find "Select what product category you want to display on the products page:" and move the arrow to "show list of product categories".

在设置>存储>外观时,“选择您想在产品页面上显示的产品类别:”并将箭头移动到“产品类别的显示列表”。

then find "Replace Page Title With Product/Category Name:" click yes.

然后找到“用产品/类别名称替换页面标题:”点击yes。

Then go to the appearance>menu and click on menu. If you scroll down you will see that the product categories you created can be added to your menu. I have put them as sub items to my shop. When someone clicks on the shop, the first page is the list of product categories. If they click on a category, they get a list of products in that category.

然后到外观>菜单,点击菜单。如果向下滚动,您将看到您创建的产品类别可以添加到您的菜单中。我把它们当作我商店的分项。当有人点击商店时,第一页是产品类别的列表。如果他们点击一个类别,他们会得到一个类别的产品列表。

I think this is what you are trying to achieve.

我想这就是你想要达到的目标。

My site is: www.greenhillsoaps.com

我的网站是:www.greenhillsoaps.com

Hope this helps.

希望这个有帮助。

#1


7  

Try the below code.

尝试以下代码。

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

The above code you have to use inside the product template of WP E-Commerce.

以上代码必须在WP电子商务的产品模板内使用。

Steps:

步骤:

– Open the wpsc-products_page.php file. – Find the products loop statement in the code.

——打开wpsc-products_page。php文件。-在代码中找到产品循环语句。

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

– Find the products loop end statement.

-查找产品循环语句。

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

– Copy the whole block in between while and endwhile for the product loop. – Then enclose those copied code inside the below mentioned condition. – Save and check the products page.

-在产品循环期间,将整个块复制到中间。-然后将复制的代码放在下面的条件下。-保存并检查产品页面。

#2


0  

If you go to the admin panel and click on products, you will see "categories" click on that and create the categories for your products, just like individual product pages. Then in your products page, go to each product and you can select which categories they fit into.

如果你去管理面板点击产品,你会看到“类别”点击,并为你的产品创建类别,就像单独的产品页面一样。然后在你的产品页面,去每个产品,你可以选择他们适合的类别。

In settings>store>appearance find "Select what product category you want to display on the products page:" and move the arrow to "show list of product categories".

在设置>存储>外观时,“选择您想在产品页面上显示的产品类别:”并将箭头移动到“产品类别的显示列表”。

then find "Replace Page Title With Product/Category Name:" click yes.

然后找到“用产品/类别名称替换页面标题:”点击yes。

Then go to the appearance>menu and click on menu. If you scroll down you will see that the product categories you created can be added to your menu. I have put them as sub items to my shop. When someone clicks on the shop, the first page is the list of product categories. If they click on a category, they get a list of products in that category.

然后到外观>菜单,点击菜单。如果向下滚动,您将看到您创建的产品类别可以添加到您的菜单中。我把它们当作我商店的分项。当有人点击商店时,第一页是产品类别的列表。如果他们点击一个类别,他们会得到一个类别的产品列表。

I think this is what you are trying to achieve.

我想这就是你想要达到的目标。

My site is: www.greenhillsoaps.com

我的网站是:www.greenhillsoaps.com

Hope this helps.

希望这个有帮助。