• Hello,

    My directory will contain many categories. Selecting the appropriate subset will be very inconvenient using the dropdown in front end.

    Is there a way to change it so the list remains open, can be scrolled etc.?

    Kind regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Shnipsel

    (@schnipsel13)

    I’ve done some modifications, now it works better for me and I’d like to share it…

    1. Using <optgroup> for the first level of categories gives a better overview. You can do it by changing _submit.php (@68) (search for function ldl_submit_multi_categories_dropdown):

    foreach ($categories as $key => $cat) {
    	$result .= "<optgroup label=\"".$cat->name."\">";
    	$result .= get_child_categories($cat->term_id,LDDLITE_TAX_CAT);
    	$result .= "</optgroup>";
    }

    2.) Correct the “brute force”   tabbing in function get_child_categories (in file _submit.php):

    2.1) change $indent to 0:
    function get_child_categories($parent_id,$tax,$indent = 0){
    (this is because the optgroup is the first indent level, no need to indent the next level too)

    2.2) indenting disturbs the filter, so we need to add a real space character in this function in the $child_cat_name. The following code also takes the $indent=0 of 2.1 into account:

    if ($indent) {
    	$child_cat_name = str_repeat('&nbsp;&nbsp;', $indent).' '.$child_term->name;
    }else{
    	$child_cat_name = $child_term->name;
    }

    3.) Update chosen jquery plugin:

    • Download from https://github.com/harvesthq/chosen/releases/
    • Copy to \wp-content\plugins\ldd-directory-lite\public\plugins
    • Add the init to chosen.jquery.min.js as in previous version, I’ve copied the code below in case you didn’t preserve it

    Init code for chosen:

    jQuery(document).ready(function(){
        jQuery(".multi_select_chosen").chosen({search_contains: true, no_results_text: "Oops, nothing found!"});
    });

    DONE. Now the category selector is more subcategory friendly and filter works for partial words (which is a huge benefit for usability).

    • This reply was modified 6 years, 7 months ago by Shnipsel.
    Thread Starter Shnipsel

    (@schnipsel13)

    Hi LDD,

    I wonder if the above feature will make it into the official plugin someday. Actually today I messed up my code base by applying your update, overwriting my own stuff. Lucky me, I had posted the modifications here. ??

    If it will make it into the plugin, there are btw some more changes to be done to make preselection of categories (ie. when editing an entry). It’s not much more than passing $selection on to get_child_categories() for get_selected() to work properly there.

    All the best

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘changing category selector’ is closed to new replies.