Support » Plugin: Beautiful taxonomy filters » Style parent / children taxonomies in dropdown?

  • Hello,

    Jonathan – I wanted to first say thank you for the fantastic plugin.

    One thing I’m slightly stuck on is styling the child taxonomies in the drop down. I’d like them to have a different background colour to differentiate from the parent taxonomies.

    Is this something that can be done?

    Thanks in advance,
    Ian

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Jonathandejong

    (@jonathandejong)

    Hi @ianbatten

    Unfortunately select2 does not support pushing over the individual options classes from the select element. The select elements options have class names like depth-0 and depth-1 but select2 does not.

    I have plans to replace select2 with choices.js at some point but time is slim 🙂

    Ah okay, that’s a shame. Would there be any way to apply a style to the children/parent?

    I’ve used the filter you posted a while back in the forum to add a dash in front of the child name. But ideally looking for a different colour!

    Thanks again.

    Plugin Author Jonathandejong

    (@jonathandejong)

    Hmmm have you tried wrapping the content in a <span class=”select-child”> using that filter?

    I can’t say I have – could you explain a little futher how you mean?

    Sorry just to follow, this was the code I used. Can this be modified in a way so rather than adding a dash/indent, it can give the option a different class?

    //Add visual information when a terms are children/grandchildren etc.
    add_filter('beautiful_filters_term_name', 'custom_term_name', 10, 3);
    function custom_term_name($term_name, $category, $depth){
    
        //We have indentation
        if($depth !== 0){
            $indent = '';
            //Add one – for each step down the hierarchy, like WP does in admin.
            for($i = 0; $i < $depth; $i++){
                $indent .= '–';
            }
            return $indent . ' ' . $term_name;
        }
        return $term_name;
    
    }
    Plugin Author Jonathandejong

    (@jonathandejong)

    Hi!

    Yeah I have not tried this myself but you might be able to do something like this:

    
    add_filter('beautiful_filters_term_name', 'custom_term_name', 10, 3);
    
    /**
     * Add visual information when a terms are children/grandchildren etc.
     *
     * @param string @term_name
     * @param object $category
     * @param int $depth
    
     * @return string
     */
    function custom_term_name( $term_name, $category, $depth ) {
        if($depth !== 0){
    			// This is a child term!
    			return sprintf( '<span class="child-term">%s</span>', $term_name );
        }
    
        return $term_name;
    }
    
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Style parent / children taxonomies in dropdown?’ is closed to new replies.