• Resolved Sergio

    (@webowebetes)


    David, thank you very much for your great work on this plugin! This is probably an easy task, but I’ve been searching and can’t seem to find a solution.

    Is it possible to get a list of tags without commas? I’m trying to print the attachment_tags as css selectors, so I can manipulate them. But they print as “tag1, tag2, tag3.” I’m using [+terms:attachment_tag,raw+] on my template to get the list.

    Is there a way to remove or filter those commas to get a “tag1 tag2 tag3” kind of list or to get just the tags without the commas?

    Thank you very much in advance!

    Best regards.

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

    (@dglingren)

    Good to hear from you again, and thanks for your question.

    Removing the commas from the tags list reminded me of this earlier topic and the other topics I referenced there:

    set title to be filename stripping characters

    There have been several “clean up a value” topics over the years and I decided to make tasks like yours easier by adding a new format option value that can be used with any data substitution parameter. That removes the need for bits of PHP code to perform these simple changes. Here is a description of the new format option:

    ,str_replace(s,r) – Replace all occurrences of the “search” string (s) with the “replacement” string (r). If search and replacement are arrays, then str_replace() takes a value from each array and uses them to search and replace on subject. If replace has fewer values than search, then an empty string is used for the rest of replacement values. If search is an array and replace is a string, then this replacement string is used for every value of search. You can find complete information on “search” and “replacement”, including examples, at: https://php.net/manual/en/function.str-replace.php.
    ?
    To specify an array argument enclose the argument in braces ( “{” and “}” ) and separate elements with spaces. For example, ,str_replace( {',' '-'}, {' ' '_'} ) will change commas to spaces and dashes to underscores, while ,str_replace( {',' '-'}, ' ' ) will change both commas and dashes to spaces.

    For your application the new substitution parameter would be:

    [+terms:attachment_tag,str_replace( ',', '' )+]

    That should remove the commas and leave one space between the tag values. You might also consider using the term slug instead of the term name, since you are using the values as class attributes:

    [+terms:attachment_tag(slug),str_replace( ',', '' )+]

    That will sanitize the values in a way that might work better for you.

    I have uploaded a new MLA Development Version dated 20171109 that contains the new format option value. It would be great if you can install the Development Version and example plugin and do some testing of your own. To get the Development Version, follow the steps in this earlier topic:

    PHP Warning on media upload with Polylang

    I hope the new format option will give you the solution you need without resorting to PHP code. I will leave this topic unresolved until I hear back from you. Thanks for inspiring an MLA enhancement!

    Thread Starter Sergio

    (@webowebetes)

    It worked! Thank you so much! It’s great to have this functionality available; it opens a host of new ways to manipulate images, not only by CSS.

    Thanks again for your time and your detailed response!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Remove commas from comma-delimited lists’ is closed to new replies.