Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-05-15 19:42:47

woof
Member
Registered: 2004-08-01
Posts: 128

sort articles by id, how to display in same order as input ids?

Hello

I’m using article_custom to output specific articles by listing their ids, comma-separated, in the tag’s id attribute. I would like them to sort in the same order as typed.

TextBook warns

IMPORTANT: When a list is supplied, this does not imply a sort order.

using sort="id" defaults to ascending order

So does anyone know another way to achieve this? Thanks.

Last edited by woof (2010-05-15 19:44:40)

Offline

#2 2010-05-15 19:49:59

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: sort articles by id, how to display in same order as input ids?

woof, woof!

There is a trick for doing that:

<txp:article_custom id="5,1,4,2,3" sort="FIELD(ID,5,1,4,2,3)" />

And, if you pick the sorting order from a variable or custom field, just feed the same variable/custom field as tags-in-tags, like:

<txp:article_custom id='<txp:custom_field name="article_sorting" />' sort='FIELD(ID,<txp:custom_field name="article_sorting" />)' />

Edit: fixed typo, thanks saccade.

Last edited by maniqui (2010-08-06 15:22:57)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2010-05-15 19:57:56

woof
Member
Registered: 2004-08-01
Posts: 128

Re: sort articles by id, how to display in same order as input ids?

Thank you very much Maniqui!

Offline

#4 2010-08-06 07:47:24

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: sort articles by id, how to display in same order as input ids?

Thank you too, just what I need now :)

EDIT:
There’s a typo in the code above:

sort='FIELD(ID,<txp:custom_field name="article_sorting' />)'

should be (see the quote after “article_sorting”)

sort='FIELD(ID,<txp:custom_field name="article_sorting" />)'

Last edited by saccade (2010-08-06 07:53:24)

Offline

Board footer

Powered by FluxBB