
-
AuthorPosts
-
March 6, 2025 at 10:59 pm #1478812
Is it possible to limit the quantity of categories listed in the categories widget? There will be too many at some point to fit.
March 7, 2025 at 6:59 am #1478831Hey Tanja,
Thank you for the inquiry.
Are you using the default Categories widget? If so, you can add this filter in the functions.php file:
function avf_widget_categories_args_mod( $cat_args, $instance ) { $cat_args['number'] = 10; // Limit to 10 categories. return $cat_args; } add_filter( 'widget_categories_args', 'avf_widget_categories_args_mod', 10, 2 );
Best regards,
IsmaelMarch 7, 2025 at 7:47 pm #1478869Thank you!
March 7, 2025 at 8:27 pm #1478873.
-
This reply was modified 1 month, 1 week ago by
Sandy.
March 7, 2025 at 8:39 pm #1478875Thank you. There are two instances of the default Categories widget in use. One needs all categories listed, the other needs up to 10. How can that be done?
March 7, 2025 at 8:56 pm #1478877The functions.php file updated didn’t work. 11 entries show in the list.
March 9, 2025 at 1:51 pm #1478929Hi,
Your login in not working, but there is not a way to use the same Categories Widget twice on the same page and have two different results, such as one showing all results and the other only showing 10 with the PHP code.
Perhaps if you added a custom class to the one that you only want to show 10, some css could be used to hide all others, but I can’t find an example page on your site to examine.Best regards,
MikeMarch 10, 2025 at 2:44 pm #1479027Here is the access info. Please let me know if there’s a way to show all in some instances and show only a specified number such as 10 in others.
March 11, 2025 at 4:38 am #1479055Hi,
Thank you for the info.
This is possible, but you need to apply a different title to the widget to differentiate it from the others. We adjusted the widget title in Footer – Column 4 to Issues A, then edited the filter as follows:
/*to limit issues listed in footer category widget so it is not too long*/ function avf_widget_categories_args_mod( $cat_args, $instance ) { if($instance['title'] == 'Issues A') { $cat_args['number'] = 5; // Limit to 5 categories. } return $cat_args; } add_filter( 'widget_categories_args', 'avf_widget_categories_args_mod', 10, 2 );
We adjusted the limit to 5.
Best regards,
IsmaelMarch 11, 2025 at 2:22 pm #1479084Thank you. Can the category items be listed by date? It seems they’re listed by category name, so if there’s a growing list of, say, 100 categories, the same old 5 will always show rather than the 5 or 10 most recent.
March 12, 2025 at 6:00 am #1479124Hi,
We are not sure if it’s possible to sort the category by date, but you can try this:
/*to limit issues listed in footer category widget so it is not too long*/ function avf_widget_categories_args_mod( $cat_args, $instance ) { if($instance['title'] == 'Issues A') { $cat_args['number'] = 5; // Limit to 5 categories. $cat_args['orderby'] = 'date'; $cat_args['order'] = 'DESC'; } return $cat_args; } add_filter( 'widget_categories_args', 'avf_widget_categories_args_mod', 10, 2 );
Best regards,
IsmaelMarch 12, 2025 at 3:16 pm #1479167Thank you, this seems to work!
-
This reply was modified 1 month, 1 week ago by
-
AuthorPosts
- The topic ‘Limit quantity of categories listed in categories widget’ is closed to new replies.