Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
use custom fields as pseudo categories
I want to use custom fields as pseudo categories, that is, clicking on a value will go to a page with a list of all other articles with the same value. So if an article’s custom field called “color” has value of “blue”, I want the user to be able to click on blue and get a list of all articles with color=“blue”.
Now, I know I can bring up a list of all the “blue” articles with
<txp:article_custom color=“blue” />
But I don’t want to have to manually create a static article_custom page/form for every possible value of “color”.
I can’t figure out how to pass the variable.
Offline
Re: use custom fields as pseudo categories
floodfish wrote:
I want the user to be able to click on blue and get a list of all articles with color=“blue”.
This is untested but can you configure one article to handle all such resuests (e.g. an article in a dedicated section called, I dunno, filter or something) and pass the custom field info as variables on the end of the URL? So perhaps in your article form:
<a href="/filter?color=<txp:custom_field name='color' />" />Filter by color</a>
<a href="/filter?size=<txp:custom_field name='size' />" />Filter by size</a>
...
and then in your ‘filter’ article use smd_if to ‘read’ the URL variables:
<txp:smd_if field="urlvar:color" operator="isused">
<txp:article_custom color="{smd_if_color}" />
</txp:smd_if>
<txp:smd_if field="urlvar:size" operator="isused">
<txp:article_custom size="{smd_if_size}" />
</txp:smd_if>
...
The adi_gps plugin might be even better because it will read all the URL vars into <txp:variable />
tags so you can then access them all as <txp:variable name="color" />
and so on.
Does that give you a starting point? There’s probably a neater (perhaps even native) way of doing it but my brain’s not in gear yet and these were the only ways I could figure.
Last edited by Bloke (2009-04-23 07:50:24)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: use custom fields as pseudo categories
Thanks, Stef!
adi_gps may could just the ticket. I’m going to try with that first.
This strikes me as functionality that should be native, but that may just be my naivete.
Offline
Re: use custom fields as pseudo categories
For a more free-form solution, tags might work too. If you find you don’t really need the attribute (color) but just the attribute value (blue). Tru tags is my fave tagging plugin.
Offline