Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
<txp:article />: restrict output by custom field
Hi,
The feature idea is to have a attribute for txp:article
and/or txp:article_custom
to restrict the output (in article list) if a certain custom field has any value and/or an specific value.
Something like this
<txp:article cfield="colour" />
will output an article list of articles that has any value in the “colour” custom field.
<txp:article cfield="colour" val="red" />
will output an article list of articles that has the “red” value for the “colour” custom field
I have been looking and I think it’s not possible in 4.0.3 (please, illuminate me if i’m wrong).
I know it’s possible to sortby custom_field, o to filter article lists by keywords.
Does this feature idea make anysense or am I’m losing something?
Last edited by maniqui (2006-03-17 04:22:50)
Offline
Re: <txp:article />: restrict output by custom field
<small>Sorry for double posting.</small>
I think this can be useful to do “offsets” by custom fields.
For example, for design/layout purposes: you can have some sticky articles and you want to position them in different divs, but you dont want to call them by article ID, because you also want not to hard-code that output. Do I explain myself?
Example: you have a custom field named “position”. And then you use values like: “main” or “sidebar”.
Then you can have:
<code>
<div id=“main”>
<txp:article cfield=“position” val=“main” status=“sticky” />
<txp:article status=“live” />
</div>
<div id=“sidebar”>
<txp:article cfield=“position” val=“sidebar status=“sticky” />
</div>
</code>
That snippet will output the following:
<code>
<div id=“main”>
- One or more sticky articles (static content, like a section introduction) with the val “main” for the custom field “position”.
- Your live articles
</div>
<div id=“sidebar”>
-Some other sticky articles (static content, like secondary content) with the val “sidebar” for the custom field “position”
</div>
</code>
I’m ashamed for what I’m going to say: <small>i think this could be a great feature!</small>
But I will be more ashamed if this is possible in 4.0.3 (yeah, i know: maybe playing with “sortby=custom_n” attribute and offsets, but dont know how much “control” can you have).
Last edited by maniqui (2006-03-17 04:16:34)
Offline
#3 2006-03-17 04:32:26
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: <txp:article />: restrict output by custom field
You can already do <txp:article customfieldname="value" />
.
Alex
Offline
Re: <txp:article />: restrict output by custom field
Thanks for the reply, zem!
Wow! That works like !!! :D
Oh, as I said, you are an obscure genius…
But wait… This great feature isnt listed in the TextBook entries for txp:article and txp:article_custom
zem… i’m really impressed by that “new” trick… many many thanks…
This is very useful information, and I’m happy because I learnt something new… and now… again, TXP has increased the possibilities…
Since when is that attribute? is it listed anywhere?
Offline
Re: <txp:article />: restrict output by custom field
Remember to edit TextBook to add it :)
Offline
Re: <txp:article />: restrict output by custom field
Hi Jeremie.
I have never edit the TXB because… well… I must admit I’m a bit lazy but the truth is that my english isnt very good…
I will do that edit right now! Yes… I must go against my fears…
BTW, did you know that trick, Jeremie?
I have searched at forums, and there are few results for “customfieldname” and just one related to an attribute for txp:article_custom and it’s a hack.
Also, I found that the chh:article_custom supports the customfieldname attribute…
Offline
Re: <txp:article />: restrict output by custom field
I have edited the txp:article entry and added the attribute customfieldname="value"
Also, I have added an example at the end.
Should I inform this change anywhere? (to Destry, to the Organizing TXB forum, etc)
Finally, does txp:article_custom
also support this attribute?
edit: yes, it does.
Last edited by maniqui (2006-03-17 19:26:40)
Offline
Re: <txp:article />: restrict output by custom field
Nope it’s the first time I see it. I knew that we could filter by keyword, that’s it. It’s quite an interesting feature.
Offline
#9 2006-03-17 22:59:26
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: <txp:article />: restrict output by custom field
It works with article_custom too. You might also want to say something about the naming of custom fields – for it to work properly you’ll have to use lowercase custom field names, and make sure they don’t clash with article/article_custom tag attribute names.
Alex
Offline
Re: <txp:article />: restrict output by custom field
Eeeesh. Any chance that limitation (lowercase) would be lifted, so we could use any (non attribute) custom field’s name ?
Offline
Re: <txp:article />: restrict output by custom field
Grmbl, I have to remember to edit before I move a post.
So, post moved from the Features Ideas forum, since it’s not really one :)
Offline
Re: <txp:article />: restrict output by custom field
<blockquote>Should I inform this change anywhere?</blockquote>
Julian, so you know, all changes should be recorded in the <a href=“http://textpattern.net/wiki/index.php?title=Change_Log#Current_Change_Log_Entries”>wiki’s change log</a>. I added the relevant info and gave you credit, but feel free to edit that page so it uses your signature instead of mine.
Edit: <a href=“http://textpattern.net/wiki/index.php?title=Txp:article_custom_/”>txp:article_custom</a> has been updated.
Last edited by Elenita (2006-03-20 01:20:11)
Offline