Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-10-18 17:19:59

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

txp:article_custom sortby custom field name

<small><b>first: I dont know what happened with the title of this thread. I made some typo errors. It would be ok if any administrator can correct it. thanks.</b></small>


An article list outputted by txp:article_custom can be sorted by custom fields values.
This is not included yet in the <a href=“http://textpattern.net/wiki/index.php?title=Txp:article_custom_/”>documentation</a>

It’s as simple as using this:

<code><txp:article_custom sortby=“custom_1” sortdir=“asc” /></code>

But that nice trick doesnt work if you try to use your custom_1 name.
Example: your custom_1 field name is “price”.

<code><txp:article_custom sortby=“price” sortdir=“asc” /></code>

This wont output anything.

The “problem” with using values like “custom_1” to sort the list is that you have to remember wich is the custom field number that you want to use to sort the list.
(example: “I want to order by “price” but I cant remember: custom_1 was named “price”? or it was custom_7?”)

Finally, if this can be implemented, let me add a suggestion:
if there are troubles with using custom fields name as sortby=“price” (because, for example, it could exist a custom field named “author” for books reviews, and maybe this could cause troubles with the actual value “author” for sortby), maybe it can be done in this way:


This way, you only need to remember the name of your custom field and add a “custom_” in front.

What do you think?

Edit: all this can be applied also for < txp:article / >

(Edit: updated title. :) -Mary)

Last edited by Mary (2006-03-19 09:34:34)

La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp


#2 2005-10-19 13:50:04

From: middelburg, nl
Registered: 2004-03-03
Posts: 235

Re: txp:article_custom sortby custom field name

I don’t find it a big problem to remember chosen names for the custom fields. Just look at or print the list you defined in admin/preferences. Implementing what you want requires a function that maps user input custom field names to custom_n field numbers.


Board footer

Powered by FluxBB