• Hi, I have custom entries in the database that are filled with names of cities from visitors. Some write a blank before or after the cities name, some add an information like the state they are living in.
    I have now a loop that sorts the cities and count, how often they are given, but if the name is that slightly different, it counts (of course) as a new city.
    I already found a way to uppercase the first letter with the [format ucfirst] shortcode. But that doesn’t fix the count, but the display only.
    Does anybody have an idea, how to cut these added blanks or states, so that they are count as one?

    [set total]0[/set]
    [set ort]Aachen[/set]
    [loop type=eintrag orderby=location fields=id]
    [pass vars]
    [if field=location value={ORT}] 
    [calc]total = total + 1 [/calc]
    [else][get ort]: [get total] Eintr?ge
    [set ort][format ucfirst][field location][/format][/set]
    [calc]total = 1 [/calc]
    [/if]
    [/pass]
    [/loop]

    This is an example for what comes out there. You see that we have one blank space, one of the entries was not with uppercase first letter and I don’t know exactly what is the problem of the other one.

    Dresden: 5 Eintr?ge
    Dresden : 5 Eintr?ge
    Dresden: 4 Eintr?ge
    Dresden: 1 Eintr?ge

    • This topic was modified 6 years, 5 months ago by RalfM.
    • This topic was modified 6 years, 5 months ago by RalfM.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    How far you’re pushing the shortcodes, this looks like a tough one!

    In the latest plugin version, I added two parameters to the [format] shortcode, maybe that will help. You can split a string, for example:

    [format split=":," part=1][field location][/format]
    

    The parameter split is for “delimiters”, characters where the given string will be split. The parameter part displays a part of the split string, starting with 1.

    Another thought, looking at the code you have. Maybe it’s necessary to “clean” the location before checking if it’s equal to the previous one (variable “ort”). Inside the loop, something like:

    [set clean_ort][format ucfirst][-format split=":," part=1][field location][/-format][/format][/set]
    
    [pass vars]
    [if check={CLEAN_ORT} value={ORT}] 
    [calc]total = total + 1 [/calc]
    [else][get ort]: [get total] Eintr?ge
    [set ort][get clean_ort][/set]
    [calc]total = 1 [/calc]
    [/if]
    [/pass]
    

    Mmm, at the moment the prefixed shortcode -format doesn’t exist, so a workaround might be..

    [set clean_ort][format split=":," part=1][field location][/format][/set]
    [set clean_ort][format ucfirst][get clean_ort][/format][/set]
    

    If that works for you, I can add the prefixed shortcodes to simplify nested format.

    • This reply was modified 6 years, 5 months ago by Eliot Akira.
    Thread Starter RalfM

    (@ralfm)

    Thank you very much Eliot!
    This works perfect.
    This is my code now and it gives a list sorted by the name and shows how often it is listed.

    [set count total]0[/set][set ort]Aachen[/set][loop type=eintrag orderby=location fields=id][set clean_ort][format split=":," part=1][field location][/format][/set][set clean_ort][format ucfirst][get clean_ort][/format][/set][pass vars][if check={CLEAN_ORT} value={ORT}][calc]total = total + 1 [/calc][else][calc]count = count+1[/calc][get count]: [get ort] - [get total] Eintr?ge
    [set ort][get clean_ort][/set][calc]total = 1 [/calc][/if][/pass][/loop]

    Now there is another idea coming up: to have a list of the top 10 entries …
    I have no idea how to get a list out of a list …

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to cut a text ?’ is closed to new replies.