How To: Append/Concatenate/Edit Field URL with additional text

Hi everyone - me again!

Best WP add-on out there - I’ll say it again - but it’s flexibility is my weakness - nothing’s intuitive for me - and so I come to the experts.

I am using a loop which works great and does almost exactly what I need - I just need to add the characters “+npc” to the end of the {Field url} and I can’t figure out how:
Current code is:

<Loop type=taxonomy_term taxonomy=category order=asc parent="ParentCategory">
      <a href="{Field url}">- <Field title />
            <If loop exists type=taxonomy_term taxonomy=category id="{Field children}">
                  <Math>
                        <Field count />+<Loop><Field count /><If not last>+</If></Loop>
                  </Math>
            <Else />
                  (<Field count />)
      </a>
      <br>
            </If>
</Loop>

p.s. I know the /a is in the wrong place but I wanted to keep the (#) in the hyperlink and it still works /shrug

So - what am I missing so that the A HREF ends up being:
https://www.domain.com/category/ParentCategory/ChildCategory*+npc*/

Thanks kindly for your time even in reviewing this request, let alone helping solve it.

Great question! When rendering a template with a simple tag like Field, L&L swaps out that tag for the actual value of the field, ignoring the stuff around it that’s just regular HTML or content. So just like how you can write (<Field count />) which ends up being output as (123), you can also add characters and even other tags around the curly brace tag in your href.

So in your case it’s as easy as <a href="{Field url}+npc">

I noticed in your example that you might want “+npc” to be before the trailing slash, so you can play around with the Format tag, (specifically the slash-related features) to achieve that. There’s actually an example of doing exactly this in the docs at that link.

This might look something like <a href="{Format end_slash=false}{Field url}{/Format}+npc/">

GENIUS!

I just tried it and it worked like a charm - and your explanation make so much sense - thank you kindly.

Geez this addon is great - and @benjamin you’re the man - coming through for me again.

Thanks!

3 Likes

Thanks for the kind words, Who Cares! :stuck_out_tongue_winking_eye:

1 Like