You could show the Category widgets as a dropdown instead, if you have large number of categories.
I’m not sure how useful it is to limit categories when ordered by name
.
You might try to order by count
to display the most used categories:
add_filter( 'widget_categories_args', function( $args )
{
$args['number'] = 1;
$args['orderby'] = 'count';
$args['order'] = 'DESC';
$args['hierarchical'] = 0;
$args['hide_empty'] = 1;
return $args;
} );
but there are other options like include
and exclude
.
Note that the Category widget uses wp_list_categories()
that uses get_categories()
, that’s a wrapper for get_terms()
that uses a WP_Term_Query
object that contains the following part, in the WP_Term_Query::get_terms()
class method:
// Don't limit the query results when we have to descend the family tree.
if ( $number && ! $hierarchical && ! $child_of && '' === $parent ) {
if ( $offset ) {
$limits="LIMIT " . $offset . ',' . $number;
} else {
$limits="LIMIT " . $number;
}
} else {
$limits="";
}
The dropdown option uses wp_dropdown_categories()
.