Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-03-17 03:57:03

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

<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)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#2 2006-03-17 04:15:03

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

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)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

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

#4 2006-03-17 04:51:02

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

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?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#5 2006-03-17 05:19:11

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: <txp:article />: restrict output by custom field

Remember to edit TextBook to add it :)

Offline

#6 2006-03-17 05:41:18

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

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…


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#7 2006-03-17 05:44:14

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

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)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#8 2006-03-17 19:24:55

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

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

#10 2006-03-19 04:55:40

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

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

#11 2006-03-19 04:56:48

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

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

#12 2006-03-20 00:58:38

Elenita
Member
From: Falls Church, VA
Registered: 2004-05-16
Posts: 407
Website

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

Board footer

Powered by FluxBB