Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-05-17 03:32:25

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

Dynamic drop down list from custom field values

Say that each article has a custom field named place.
I would like textpattern to dynamically create the following:

<option value="New York">New York</option>
<option value="Boston">Boston</option>
<option value="Washington">Washington</option>
etc. etc.

There would be many articles for each city, but each city should only appear once in the list.

I have done something similar for categories:

<txp:category_list parent="places" break="">
<option value="<txp:category />"><txp:category title="1" /></option>
</txp:category_list>

QUESTION: How do I do this?

PS: Wishful thinking
It would be great if a plugin like custom_field_list existed…


Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
JapaneseStreets.com – Japanese street fashion (mostly txp)

Offline

#2 2010-05-17 04:15:19

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Dynamic drop down list from custom field values

smd_each can help you do this.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#3 2010-05-17 07:27:25

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Dynamic drop down list from custom field values

With core powered article_custom

<txp:article_custom limit="9999" sort="custom_1 asc" place="_%">
	<txp:if_different>
		<option value="<txp:custom_field name="place" />">
			<txp:custom_field name="place" />
		</option>
	</txp:if_different>
</txp:article_custom>

Or with smd_query

<txp:smd_query query="SELECT custom_1 FROM textpattern WHERE custom_1 != '' GROUP BY custom_1 ORDER BY custom_1 asc">
	<option value="{custom_1}">{custom_1}</option>
</txp:smd_query>

In both examples, the custom_1 is the column of your custom field. Top of my head, both untested. Fingers crossed, they may work.

Offline

#4 2010-05-17 15:06:56

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Dynamic drop down list from custom field values

Sorry, I assumed you had a custom_field with multiple values in each article, like a comma delimited list.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#5 2010-05-18 08:07:33

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

Re: Dynamic drop down list from custom field values

Thanks a lot, Gocom and MattD.

Gocom, your solution took care of my issue completely.

For some reason smd_query didn’t work for me, but the core powered article_custom works great. I had tried article_custom before but I wasn’t familiar with if_different, so I ended up with repeated entries. Cool stuff.

I have added a little lemon to this cocktail:

I pull the custom fields out of my url with adi_gps. Using if_variable, the following code now adds selected to the currently selected option.

<txp:article_custom limit="9999" sort="custom_1 asc" place="_%">
	<txp:if_different>
		<option <txp:if_variable name='place' value='<txp:custom_field name="place" />'>selected</txp:if_variable> value="<txp:custom_field name="place" />">
			<txp:custom_field name="place" />
		</option>
	</txp:if_different>
</txp:article_custom>

By the way, limit is set to 9999. What happens if you have more than 10,000 articles?


Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
JapaneseStreets.com – Japanese street fashion (mostly txp)

Offline

#6 2010-05-18 08:30:35

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Dynamic drop down list from custom field values

Kjeld wrote:

By the way, limit is set to 9999. What happens if you have more than 10,000 articles?

It won’t go thru all articles. You can set the limit to higher value ofcourse (99999). :-)

Offline

#7 2010-05-18 09:18:41

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

Re: Dynamic drop down list from custom field values

Gocom wrote:

It won’t go thru all articles. You can set the limit to higher value ofcourse (99999). :-)

I thought that was the top limit for some reason… I think a limit of 100,000 should probably cover me for a few weeks. ;-)

Got it, Gocom. Thanks!


Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
JapaneseStreets.com – Japanese street fashion (mostly txp)

Offline

Board footer

Powered by FluxBB