Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-04-26 20:22:51

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Filter articles using their custom field

Hi there,
I’ve got a list of articles grouped first by category. When I see all articles of one category is possible to filter them by custom fields?
All articles describe a professional guide in Tuscany. All guides are separeted by province of appartenence (that is a category). But a guide had one or more areas of interest too (like hiking, trekking etc…) and it’s set with a checkbox custom field.
How can I create, at this point, a way to restrict my list in base of guide’s specific area?

Offline

#2 2011-04-28 11:22:57

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Re: Filter articles using their custom field

I found a possible solution.
Using smd_if I check url for some variable. If used the form will print all articles with custom field value.

<txp:smd_if field="urlvar:tipologie" operator="isused">
<txp:article limit="999" sort="title" tipologie="{smd_if_tipologie}" />
<txp:else />
<txp:article limit="999" sort="title" />
</txp:smd_if>

Everything goes fine only if the value of custom field is exactly the same. But using a check-box for the custom field (glz_cf) the real values stored in database are delimeted.

How can I check if the urlvalues are contained in the custom field?

Last edited by wornout (2011-04-28 11:23:22)

Offline

#3 2011-04-28 11:51:23

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Re: Filter articles using their custom field

I’ve got it!

Adding a simple <txp:if_custom_field /> to the previous code.

<txp:smd_if field="urlvar:tipologie" operator="isused">
<txp:article limit="999" sort="title">
<txp:if_custom_field name="tipologie" match="any" separator="|" value="{smd_if_tipologie}">
<h1><txp:title /></h1>
</txp:if_custom_field>
</txp:article>
<txp:else />
<txp:article limit="999" sort="title" />
</txp:smd_if>

Now I’ve got to create the form to submit values!

Edit:

It’s possible to use soo_article_filter too. Like this:

<txp:smd_if field="urlvar:tipologie" operator="isused">
<txp:soo_article_filter tipologie="{smd_if_tipologie}">
<txp:article limit="999" sort="title" />
</txp:soo_article_filter>
<txp:else />
<txp:article limit="999" sort="title" />
</txp:smd_if>

Last edited by wornout (2011-05-10 16:14:29)

Offline

#4 2011-04-28 12:48:30

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: Filter articles using their custom field

Always nice to see people sharing solutions even if there wasn’t an input from outside. Thanks, Edoardo :)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#5 2011-05-04 17:24:45

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Re: Filter articles using their custom field

This is the code that generates a little form to choose the custom field value.
The hidden value is set to remain in the same category.
I wish it can help you!

<form action="<txp:page_url />">
<input type="hidden" name="c" value='<txp:category />' />
<select name="tipologies" onChange="this.form.submit();">
<option value="">Show all</option>
<txp:smd_each type="fixed" include='<txp:esq_glzcfvallist fieldname="tipologies" delimiter=":" />' subset="2">
<txp:smd_if field="urlvar:tipologies" operator="eq" value='{smd_var_value}'>
<option selected="selected" value="{smd_var_value}">{smd_var_value}</option>
<txp:else />
<option value="{smd_var_value}">{smd_var_value}</option>
</txp:smd_if>
</txp:smd_each>
</select>
</form>

Last edited by wornout (2011-05-06 13:49:07)

Offline

Board footer

Powered by FluxBB