Viewing 1 replies (of 1 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thank you for the question and for taking the time to dig through the support forum to find an earlier topic that matches it. In that topic you saw the use of the [+terms:category,single+] option to limit the output to a single term. I gather you need to include all of the terms but separate them by space instead of comma; is that right?

    The best way to get what you want is to clean up the [+terms:category+] value by using the mla_gallery_item_values filter provided by MLA. The basic approach is explained in this earlier support topic:

    format date

    For your application you can use this code in the filter:

    public static function mla_gallery_item_values_filter( $item_values ) {
        /*
         * We use a shortcode parameter of our own to apply our filters on a gallery-by-gallery basis,
         * leaving other [mla_gallery] instances untouched. If the "my_filter" parameter is not present,
         * we have nothing to do.
         */
        if ( ! isset( self::$shortcode_attributes['my_filter'] ) ) {
            return $item_values; // leave them unchanged
        }
    
        if ( 'format terms' == self::$shortcode_attributes['my_filter'] ) {
            $object_terms = wp_get_object_terms ( absint( $item_values['attachment_ID'] ), 'category', array( 'fields' => 'slugs' ) );
            $item_values['terms:category'] = implode( ' ', $object_terms );
        }
    
    return $item_values;
    } // mla_gallery_item_values_filter

    The code replaces the [+terms:category+] value with a space-delimited list of the term “slugs”. You want the slugs because they will always be lowercase letters and contain dashes in place of spaces within the terms, e.g., “My Term” will become “my-term” which is a much better choice for the “class” attribute.

    Once the code is active on your site you can add my_filter="format terms" to your shortcode to activate the code. You could also replace [+terms:category+] in your template with something like [+my_category_slugs+] and then simplify the filter to be something like:

    public static function mla_gallery_item_values_filter( $item_values ) {
        $object_terms = wp_get_object_terms ( absint( $item_values['attachment_ID'] ), 'attachment_category', array( 'fields' => 'slugs' ) );
        $item_values['my_category_slugs'] = implode( ' ', $object_terms );
    
    return $item_values;
    } // mla_gallery_item_values_filter

    Your new substitution parameter won’t interfere with any other code, but it will be created for every shortcode in your application.

    I am marking this topic resolved, but please update it if you have any problems with the suggested solution or any other questions about using the filters to get the results you need. Thanks for your interest in the plugin.

Viewing 1 replies (of 1 total)

The topic ‘Category Classes added include a comma, how to remove’ is closed to new replies.