Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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.

    #1478831

    Hey 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,
    Ismael

    #1478869

    Thank you!

    #1478873

    .

    • This reply was modified 1 month, 1 week ago by Sandy.
    #1478875

    Thank 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?

    #1478877

    The functions.php file updated didn’t work. 11 entries show in the list.

    #1478929

    Hi,
    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,
    Mike

    #1479027

    Here 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.

    #1479055

    Hi,

    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,
    Ismael

    #1479084

    Thank 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.

    #1479124

    Hi,

    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,
    Ismael

    #1479167

    Thank you, this seems to work!

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Limit quantity of categories listed in categories widget’ is closed to new replies.