Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Perform functions on custom fields?
I’ve got a custom field called priority
which is a number 1 to 99 that I’ll use to arrange articles on my homepage with an article_custom
. So far so good. But now I’d like to have a list in the sidebar of article pages that also uses the custom field, but increases the score for articles that share a section with the current context.
In other words, if article A has the score 30 and article B has 35, the order will be A, B on the homepage but B, A on the page of an article that shares article B’s section.
Any ideas? Perhaps a plugin? Or maybe something like
<txp:article_custom sort="<txp:php>... something about custom_2 unless section=current section then custom_2 + 20 ...</txp:php>" />
Am I heading in the right direction?
Yes, I have tried turning it off and on.
Offline
Re: Perform functions on custom fields?
alesh wrote:
Am I heading in the right direction?
I think you even don’t need <txp:php>
, this should work (untested):
<txp:article_custom sort='custom_2 + IF(Section = ''<txp:section />'', 20, 0)' />
Offline
#3 2013-08-21 21:34:33
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: Perform functions on custom fields?
Wow! Please let this work, Lord Query van Crossnesting :))
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Offline
Re: Perform functions on custom fields?
Yup. That doSlash() is hilarious, especially as it can not sanitize anything, but quoted values. Wrapping the order clause to it doesn’t protect you from SQL injections, since it basically only quotes.
Thankfully, the deprecated MySQL extension we currently use doesn’t support query delimiters and MySQL itself can not run queries in order clause. PDO on the other hand, is different story.
Offline
Re: Perform functions on custom fields?
Gocom wrote:
Yup. That doSlash() is hilarious, especially as it can not sanitize anything, but quoted values.
+100%, additionally it fubars quoted column names like `rock'n'roll`
.
Revenant à nos moutons, the simplest (avoiding core modification) solution I can see is a direct db query (with smd_query
or etc_query
or php
), with ORDER BY
clause as above. Any other ideas?
Offline
#7 2013-08-22 15:27:05
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: Perform functions on custom fields?
etc wrote:
Any other ideas?
Building a PHP array (something I definitely can’t help with) from an article_custom tag’s custom field values and IDs, doing the maths on it, ordering it by value and filling an article_custom tag with the IDs like Jeff/Jsoo did here.
{Edited just to add the IDs, hey.}
Last edited by uli (2013-08-22 15:31:57)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Perform functions on custom fields?
I’m dumb, that was rather obvious:
<txp:php>$section = parse('<txp:section />'); mysql_query("SET @section='$section'");</txp:php>
<txp:article_custom sort="custom_2 + IF(Section = @section, 20, 0)" />
Last edited by etc (2013-08-24 19:38:52)
Offline
Pages: 1