Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » How do I…?
  3. » Sort Order

#1 2011-11-11 19:03:33

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 335
Website

Sort Order

I am trying to get the following to sort, simply in the order of the comma separated list.

I am using article_custom to output articles by listing their categories, comma-separated, from three custom fields. That works fine, but I would like the order to be simply the order of the comma separated list. None of the standard TXP sorting options appear to do that.

Here is the code:

<txp:article_custom category='<txp:custom_field name="field 1" />,<txp:custom_field name="field 2" />,<txp:custom_field name="field 3" />' listform="menu" section="maps" />

The menu form:

<txp:permlink><txp:title /></txp:permlink>

I have tried adapting other similar examples from the forum without success. How can I make this work?

Offline

#2 2011-11-11 19:30:03

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,549
Website GitHub Twitter

Re: Sort Order

Hi

could you explain more what order you want to achieve?

Ex: cat1,cat2,cat3

do you try to list cat1 articles and then cat2 articles and then cat3 articles?

Offline

#3 2011-11-11 19:31:07

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Offline

#4 2011-11-11 21:20:17

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 335
Website

Re: Sort Order

Dragondz wrote:

Hi
could you explain more what order you want to achieve?
Ex: cat1,cat2,cat3
do you try to list cat1 articles and then cat2 articles and then cat3 articles?

Dragondz, thank you. You shook my brain to what should have been an obvious solution:

<txp:article_custom category='<txp:custom_field name="field 1" />' listform="menu" section="maps" /> 
<txp:article_custom category='<txp:custom_field name="field 2" />' listform="menu" section="maps" /> 
<txp:article_custom category='<txp:custom_field name="field 3" />' listform="menu" section="maps" />

The above works great. The three txp article calls seems less elegant than one, but it works. I’m happy.

Maruchan, I had tried taking the example from that link, and using my brilliant deductive skills a wild guess, I tried the following:

 <txp:article_custom category='<txp:custom_field name="field 1" />,<txp:custom_field name="field 2" />,<txp:custom_field name="field 3" />' listform="menu" section="maps" sort="field('category',<txp:custom_field name="field 1" />,<txp:custom_field name="field 2" />,<txp:custom_field name="field 3" />)" />

… it didn’t work.

I am good with the first solution though. If there is something obvious that fixes the second example it would be great to know for the future.

Offline

#5 2011-11-11 21:53:07

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Sort Order

You need single quotes for the sort value, too. I’m not sure about the two single quotes around category, but you can experiment with that.

<txp:article_custom category='<txp:custom_field name="field 1" />,<txp:custom_field name="field 2" />,<txp:custom_field name="field 3" />' listform="menu" section="maps" sort='field(''category'',<txp:custom_field name="field 1" />,<txp:custom_field name="field 2" />,<txp:custom_field name="field 3" />)' />

Offline

#6 2011-11-15 15:02:25

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Sort Order

I think the quotes you enter in the sort attribute value are escaped before the query is executed, so this might work, but only of the custom_field stuff returns numbers instead of strings:

<txp:article_custom category='<txp:custom_field name="field 1" />,<txp:custom_field name="field 2" />,<txp:custom_field name="field 3" />' listform="menu" section="maps" sort="field(category,<txp:custom_field name="field 1" />,<txp:custom_field name="field 2" />,<txp:custom_field name="field 3" />)" />

Offline

  1. Index
  2. » How do I…?
  3. » Sort Order

Board footer

Powered by FluxBB