2016-12-28 80 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); ?> 

我一直用这个代码:)