Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-07-17 16:00:44

minusf
Member
Registered: 2005-02-15
Posts: 104

article_custom sort by id's in an arbitrary way

hi there,

please consider the following example:

<txp:article_custom id="29,88,21,22,18,16,19" />

for some reason i thought it logical, that if i specify a particular list of id’s for article_custom, the list will be kept according to the list of id’s. unfortunately this is not the case. they are still sorted (in this case using sort’s default value of posted desc). this makes article_custom far less flexible.

i know i can use a custom tag but it seems like a lot of fuss for a simple feature like this.

any ideas about this?


we is experts™

Offline

#2 2009-07-17 16:20:49

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: article_custom sort by id's in an arbitrary way

You can use MySQL’s field function in article_custom’s sort attribute to preserve an arbitrary sort order (such as your list of IDs), as shown here. Note that one of our new Txp devs cautions against this kind of MySQL-specific coding.

Edit: Just realized my example is missing the column name for sorting, so won’t do anything! Just corrected it.

Last edited by jsoo (2009-07-17 16:53:37)


Code is topiary

Offline

#3 2009-07-20 19:46:04

minusf
Member
Registered: 2005-02-15
Posts: 104

Re: article_custom sort by id's in an arbitrary way

thanks for the pointers.

i think the methods described there are not better or more convenient
on the long run though. custom fields accomplish the job nicely,
i just ran afoul on an assumption about default functionality,
happens all the time :]


we is experts™

Offline

#4 2009-07-20 20:50:27

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: article_custom sort by id's in an arbitrary way

I didn’t mean you should use a custom field, simply that you can extend your example to this:

<txp:article_custom id="29,88,21,22,18,16,19" sort="field('ID',29,88,21,22,18,16,19)" /> 

to get the sort order you want.


Code is topiary

Offline

#5 2009-07-26 22:51:31

photonomad
Member
Registered: 2005-09-10
Posts: 290
Website

Re: article_custom sort by id's in an arbitrary way

jsoo: I am curious if you have an opinion (or would venture to guess) as to how I might use sort=“field()” with the stw_category_tree plugin? I just posted my full question here in the stw_category_tree forum.

Offline

#6 2009-07-27 01:19:15

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: article_custom sort by id's in an arbitrary way

Don’t know a thing about that plugin. You would need it to produce a comma-separated list of category names, with each item quoted (and offhand I suppose you would have to escape the quote marks, given that this would already be a tag-within-tag situation using both single and double quotes), and of course those categories would have to correspond to Txp article categories (don’t know if the plugin has an entirely separate category table or uses Txp categories). In the example above the IDs don’t need to be quoted because they’re numbers.


Code is topiary

Offline

Board footer

Powered by FluxBB