Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-09-20 21:29:17

cykla
New Member
From: Boise, ID
Registered: 2007-09-20
Posts: 9
Website

Filter Article List with Custom Field Value

I’m already using 2 categories (using rss-unlimited-categories) for filtering articles

mysite.com/section/?c=fruit

From this list of articles relating to fruit i’d like the user to select from a drop-down a custom field value. Such as a custom field for where the fruit“Originated”.

So upon selecting from a preset options combo box the page would reload the article list with the fruit category only showing articles that have the custom field “Originated” with the value “South America” (or whatever they selected)

I understand on my rss_unlimited_categories_article_list form I can include an if clause to check the custom fields value. My problem is gathering the submitted information from the dropdown in order plug into the if_custom_field.

I’m having problems switching in between PHP/Texpattern Tags to pull from form [post] request and also tried passing url parameters with no success.

Any help is appreciated! Thank you!

Offline

#2 2007-09-21 17:34:03

cykla
New Member
From: Boise, ID
Registered: 2007-09-20
Posts: 9
Website

Re: Filter Article List with Custom Field Value

Alright, I may have over complicated this. I basically just need some advice on how to pass a user-selected html form variable from an article list page, reload, and grab it in the article list form.

My goal is to filter out the article list when a user selects a custom_field.
I’m aware I can’t go in and out of PHP like this in Textpattern
Something like a working version of this:

<txp:php> if ($_POST['location'])
{echo "<txp:if_custom_field name='location' val='".$_POST['location']."'>"; }?>
</txp:php>

<div class="listproperty-result">
<div class="imageContainer"><txp:article_image thumbnail="1" /></div>
<h4 class="listhead"><txp:permlink><txp:title /></txp:permlink>
<span class="price"><txp:custom_field name="Price" /></span>
<span class="city"><txp:custom_field name="City" /></span></h4>
<p><txp:rss_auto_excerpt length="170" linktext="More Information" striptags="1"/>
</p>
<div class="clearit"></div>
</div>

<txp:php>
if ($_POST['location'])
{echo "</txp:if_custom_field>"; }?>
</txp:php>

Offline

#3 2007-09-21 17:45:34

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Filter Article List with Custom Field Value

Something like this perhaps (not tested)?

<txp:php>
if (ps('location'))
  echo if_custom_field(array('name'=>'location', 'val'=>ps('location')), '
    <div class="listproperty-result">
      <div class="imageContainer"><txp:article_image thumbnail="1" /></div>
      <h4 class="listhead">
        <txp:permlink><txp:title /></txp:permlink>
        <span class="price"><txp:custom_field name="Price" /></span>
        <span class="city"><txp:custom_field name="City" /></span>
      </h4>
      <p><txp:rss_auto_excerpt length="170" linktext="More Information" striptags="1"/></p>
      <div class="clearit"></div>
    </div>
  ');
</txp:php>

Offline

#4 2007-09-21 18:43:05

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Filter Article List with Custom Field Value

I’m not sure if you want this (what you currently have):

<txp:php>
if (ps('location'))
  echo if_custom_field(array('name'=>'Location', 'val'=>ps('location')), '
    <!-- html code here -->
  ');
else
  echo parse('<!-- other html code here -->');
</txp:php>

or:

<txp:php>
if (ps('location'))
  echo if_custom_field(array('name'=>'Location', 'val'=>ps('location')), '
    <!-- html code here -->
    <txp:else />
    <!-- other html code here -->';
  ');
</txp:php>

Offline

#5 2007-09-21 19:17:41

cykla
New Member
From: Boise, ID
Registered: 2007-09-20
Posts: 9
Website

Re: Filter Article List with Custom Field Value

That makes sense.

I need an html form on the article list page that requests to itself (i’m not sure how to do this).

Page Template: article_list

<txp:if_article_list>
...
<form action="[self]" method="get">
<p><select name="location">
<option selected="selected">Filter By Location</option>
<option>Boise</option>
<option>Eagle</option>
<option>Star</option>
</select>
<button type="submit" />
</p>
</form>
...
<txp:rss_unlimited_categories_article_list form="static_headline_properties" sortby="custom_4" sortdir="asc" />
...
</txp:if_article_list>
...
<txp:if_individual_article>
<txp:article form="property_detail" />
</txp:if_individual_article>

My article_list form named “static_headline_properties” should check to see if this ‘location’ form html form variable exists. If it does it will use the value along with the txp:if_custom_field function to only show articles with that custom field value. If the form variable does not exist no filtering will take place and all articles will show.

Article Form: static_headline_properties

<txp:php>
if (ps('location'))
  echo if_custom_field(array('name'=>'Location', 'val'=>ps('location')), '
    <!-- html/txp article title info -->
  ');
</txp:php>

Does this make sense? Is there a better way to accomplish this? Thank you for all your help!

Last edited by cykla (2007-09-21 19:39:14)

Offline

#6 2007-09-21 21:34:02

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Filter Article List with Custom Field Value

If you planned on using $_POST, then your form method should be post as well (not get).
I’m not sure why you’re using rss_unlimited_categories_article_list instead of the normal txp:article tag.

For the article_list part I’d go for:

<txp:php>
  echo article(array('list form'=>'static_headline_properties', 'sort'=>'custom_4 ASC', 'Location'=>ps('location')));
</txp:php>

And only put <!-- html/txp article title info --> in the static_headline_properties form.

That’s far more efficient, because it only grabs the articles from the database that you really want to display.

Offline

#7 2007-09-21 21:53:21

cykla
New Member
From: Boise, ID
Registered: 2007-09-20
Posts: 9
Website

Re: Filter Article List with Custom Field Value

I apologize. I forgot to mention that these articles are already listed by category hence the use of ‘rss_unlimited_categories_article_list’.

‘rss_unlimited_categories_article_list’ doesn’t seem to support the customfieldname=“value” attribute like txp:article does. I need to come up with an alternate method to filter by custom field. This is why I was trying to code inside article form ‘static_headline_properties’ using the if_custom_field.

Thanks!

Offline

Board footer

Powered by FluxBB