Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-10-03 08:38:25

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,012
Website GitHub Mastodon Twitter

[SOLVED] linklists

Is there a way to add an and just before the final entry in linklists?

ie.

<txp:linklist break=", " wraptag="p" category="thanks"><a rel="external" href="<txp:link_url />"><txp:link_name /></a></txp:linklist>

I am trying to make the above to parse like

Bloke, Oleg, Phil, ruud, and wet

and not

Bloke, Oleg, Phil, ruud, wet


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2018-10-03 09:09:00

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,599
Website

Re: [SOLVED] linklists

Try using txp:if_last_link and break="":

<txp:linklist break="" wraptag="p" category="thanks"><a rel="external" href="<txp:link_url />"><txp:link_name /></a><txp:if_last_link> and <txp:else/>, </txp:if_last_link></txp:linklist>

TXP Builders – finely-crafted code, design and txp

Offline

#3 2018-10-03 10:05:10

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,012
Website GitHub Mastodon Twitter

Re: [SOLVED] linklists

jakob wrote #314348:

Try using txp:if_last_link and break="":

<txp:linklist break="" wraptag="p" category="thanks"><a rel="external" href="<txp:link_url />"><txp:link_name /></a><txp:if_last_link> and <txp:else/>, </txp:if_last_link></txp:linklist>

Hi Julian

This returns:

Bloke, Oleg, Phil, ruud, wet and


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#4 2018-10-03 10:09:15

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,012
Website GitHub Mastodon Twitter

Re: [SOLVED] linklists

but this one works… and includes the Oxford comma:)

<txp:linklist break="" wraptag="p" break", " category="thanks">
<txp:if_last_link>and </txp:if_last_link><a rel="external" href="<txp:link_url />"><txp:link_name /></a>
</txp:linklist>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2018-10-03 10:16:00

etc
Developer
Registered: 2010-11-11
Posts: 5,057
Website GitHub

Re: [SOLVED] linklists

You can do it with CSS:

a+a::before { content: ', ' }
a+a:last-child::before { content: ' and ' }

Offline

#6 2018-10-03 10:16:03

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,599
Website

Re: [SOLVED] linklists

Of course you’re right.

Or this if you don’t want the oxford comma:

<txp:linklist break="" wraptag="p" category="thanks"><txp:if_last_link> and </txp:if_last_link><a rel="external" href="<txp:link_url />"><txp:link_name /></a><txp:if_last_link><txp:else/>, </txp:if_last_link></txp:linklist>

Maybe <txp:if_last_link not>, </txp:if_last_link> also works for the second instance of the tag.


TXP Builders – finely-crafted code, design and txp

Offline

#7 2018-10-03 11:10:59

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,012
Website GitHub Mastodon Twitter

Re: [SOLVED] linklists

jakob wrote #314354:

Of course you’re right.

Or this if you don’t want the oxford comma…

Hi Julian, Thanks!!! but the Oxford comma is good. The code might be of use to others though.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#8 2018-10-03 11:27:11

etc
Developer
Registered: 2010-11-11
Posts: 5,057
Website GitHub

Re: [SOLVED] linklists

Just make sure that the link list contains more than one link, otherwise you’ll get and wet.

Offline

#9 2018-10-03 11:31:05

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,012
Website GitHub Mastodon Twitter

Re: [SOLVED] linklists

etc wrote #314359:

Just make sure that the link list contains more than one link, otherwise you’ll get and wet.

Hi Oleg,
Indeed. I use it under the vimeo GDPR warning here and in many other pages. That is, I only use it when there is more than one video in the list. The snippet I use is here.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB