2014-05-21 42 views
1

有沒有辦法獲得當前的分類(分類或標籤)發佈數?我遇到的代碼只對類得到當前分類的帖子數

<?php 
    $cat = get_query_var('cat'); 
    $categories = get_categories('include='.$cat); 
    if ($categories) { 
     foreach($categories as $category) { 
      echo '' . $category->count; 
     } 
    } 
?> 
+1

你想要一個**類別**或該類別的**術語的帖子數?也就是說,你想要所有具有「類別X」的帖子的數量,或所有具有任何類別(「類別X」或「類別Y」或「類別Z」)的所有帖子的數量? – MikO

+0

Hi MikO,謝謝你的回覆。我想要檢索當前標籤的帖子數。 – Origami

回答

1

我想你可以做這樣的事情:

// Set the name of your Taxonomy or get it as you're currently doing 
// It can be category, tag or custom taxonomy name 
$taxonomy = "your_taxonomy"; 

$total_count = 0; 

// Get all the terms in your Taxonomy and add the count for each term 
foreach (get_terms($taxonomy) as $term) { 
    $total_count += (int) $term->count; 
} 

echo $total_count; 

這會給你已在指定的任何條款的所有帖子的計數分類標準your_taxonomy,我知道你想要什麼...