2016-12-28 79 views

回答

0
<?php  
$args = array(
'get' => 'all', 
'hide_empty' => 0 
); 

$categories = get_categories($args); 
echo count($categories);  
?> 
0

一種更直接的方式(也許更快?)

global $wpdb; 

$categories_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->terms"); 

echo "<p>Categories count is {$categories_count}</p>"; 
+0

不是'wp_terms'表中的所有內容都是一個類別 –

0

簡單的方法來計算類別是: 1)首先取從WordPress的 2所有類別),使用簡單的PHP功能可按 盡數完整的代碼將是這樣的:

<?php $args = array('parent' => 0, 'hide_empty' => 0); 

$categories = get_categories($args); 

echo "Total categories : ".count($categories); ?> 

我一直用這個代碼:)