获取带有自定义分类的WooCommerce产品

时间:2017-11-09 作者:Sanjay Yadav

我正在尝试为woocommerce产品创建自定义类别。然后我要获取特定类别的数据。这是我的分类代码,

// Register Custom Taxonomy

    add_action( \'init\', \'custom_taxonomy_Item\' );
    function custom_taxonomy_Item()  {
    $labels = array(
        \'name\'                       => \'Items\',
        \'singular_name\'              => \'Item\',
        \'menu_name\'                  => \'Item\',
        \'all_items\'                  => \'All Items\',
        \'parent_item\'                => \'Parent Item\',
        \'parent_item_colon\'          => \'Parent Item:\',
        \'new_item_name\'              => \'New Item Name\',
        \'add_new_item\'               => \'Add New Item\',
        \'edit_item\'                  => \'Edit Item\',
        \'update_item\'                => \'Update Item\',
        \'separate_items_with_commas\' => \'Separate Item with commas\',
        \'search_items\'               => \'Search Items\',
        \'add_or_remove_items\'        => \'Add or remove Items\',
        \'choose_from_most_used\'      => \'Choose from the most used Items\',
    );
    $args = array(
        \'labels\'                     => $labels,
        \'hierarchical\'               => true,
        \'public\'                     => true,
        \'show_ui\'                    => true,
        \'show_admin_column\'          => true,
        \'show_in_nav_menus\'          => true,
        \'show_tagcloud\'              => true,
    );
    register_taxonomy( \'item\', \'product\', $args );
    register_taxonomy_for_object_type( \'item\', \'product\' );
    } 
在此之后,我将在我的theme woo commerce目录中创建一个自定义分类模板“taxonomy-product\\u cat-Item.php”。在此之后,我无法获取特定类别的数据。老实说,我不知道该怎么做。任何帮助

1 个回复
SO网友:Aniruddha Gawade

模板名称应为:taxonomy-item.php.它应该是分类slug,没有product-cat.

结束