Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 类别名称以及woocomerce中该类别的产品总数_Wordpress_Woocommerce - Fatal编程技术网

Wordpress 类别名称以及woocomerce中该类别的产品总数

Wordpress 类别名称以及woocomerce中该类别的产品总数,wordpress,woocommerce,Wordpress,Woocommerce,有人能告诉我如何在类别存档页面中显示类别标题和该类别中的产品编号,如类别1(10) 网址是 有人能帮我吗。。。。。。。。。。。。。。 我尝试过这个,但它显示了网站的全部产品。我只想要那一类的产品 <h1><?php woocommerce_page_title(); global $woocommerce_loop; do_action( 'woocommerce_before_subcategory', $category );

有人能告诉我如何在类别存档页面中显示类别标题和该类别中的产品编号,如类别1(10)

网址是

有人能帮我吗。。。。。。。。。。。。。。 我尝试过这个,但它显示了网站的全部产品。我只想要那一类的产品

<h1><?php woocommerce_page_title(); 


global $woocommerce_loop;
 do_action( 'woocommerce_before_subcategory', $category ); 

                    echo apply_filters( 'woocommerce_subcategory_count_html', ' <mark class="count">(' . $category->count . ')</mark>', $category );
        ?>  


        </h1>

要列出所有类别以及产品数量:

$terms = get_terms( 'product_cat' ); 
foreach( $terms as $term ) 
{
    echo 'Product Category: '
        . $term->name
        . ' - Count: '
        . $term->count;
} 
如果您有类别ID:

$term = get_term( CAT_ID, 'product_cat' );   //Replace your category ID here
echo 'Product Category: '
    . $term->name
    . ' - Count: '
    . $term->count;

要列出所有类别以及产品数量,请执行以下操作:

$terms = get_terms( 'product_cat' ); 
foreach( $terms as $term ) 
{
    echo 'Product Category: '
        . $term->name
        . ' - Count: '
        . $term->count;
} 
如果您有类别ID:

$term = get_term( CAT_ID, 'product_cat' );   //Replace your category ID here
echo 'Product Category: '
    . $term->name
    . ' - Count: '
    . $term->count;

我能解决这个问题

<h1><?php woocommerce_page_title(); 



global $wp_query;
// get the query object
$cat_obj = $wp_query->get_queried_object();


if($cat_obj)    {
    $category_name = $cat_obj->name;
    $category_desc = $cat_obj->description;
    $category_ID  = $cat_obj->term_id;
}


$term = get_term( $category_ID, 'product_cat' ); 
echo '('. $term->count . ')';


?>      
        </h1>


将其放在“archive product.php”中

我能够解决这个问题

<h1><?php woocommerce_page_title(); 



global $wp_query;
// get the query object
$cat_obj = $wp_query->get_queried_object();


if($cat_obj)    {
    $category_name = $cat_obj->name;
    $category_desc = $cat_obj->description;
    $category_ID  = $cat_obj->term_id;
}


$term = get_term( $category_ID, 'product_cat' ); 
echo '('. $term->count . ')';


?>      
        </h1>


将其放在“archive product.php”中

这将反映所有类别及其计数。如何在每个类别存档页面中显示标题为的每个类别的计数?????试试这个,希望它能起作用:全局$wp\u查询$cat_obj=$wp_query->get_queryed_object()$term=get_term($cat_obj->term_id,'product_cat');回显“产品类别:”$术语->名称。“-计数:'$术语->计数;这将反映所有类别及其计数。如何在每个类别存档页面中显示标题为的每个类别的计数?????试试这个,希望它能起作用:全局$wp\u查询$cat_obj=$wp_query->get_queryed_object()$term=get_term($cat_obj->term_id,'product_cat');回显“产品类别:”$术语->名称。“-计数:'$术语->计数;