number
(integer) The maximum number of terms to return. Default is to return them all.
http://codex.wordpress.org/Function_Reference/get_terms
所以。。。
$terms = get_terms(\'new_category\',array(\'number\' => 5));
但很有可能你的一些条款永远不会出现。根据排序顺序,您将获得前五个或后五个(在本例中)。您可能需要这样的内容:
$terms = get_terms(\'category\');
if (!is_wp_error($terms)) {
$pick = ($pick <= count($terms)) ?: count($terms);
$rand_terms = array_rand($terms, $pick);
echo \'<ul>\';
foreach ($rand_terms as $key => $term) {
$term = $terms[$term];
$term_link = get_term_link( $term );
var_dump($term_link);
if (!is_wp_error($term_link)) {
echo \'<li><a href="\' . $term_link . \'"><div>\' . $term->name . \'</div></a></li>\';
}
}
echo \'</ul>\';
}