Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
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
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
Re: Sort Order
Offline
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
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
Pages: 1