Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-07-05 14:33:04

kitto
Member
From: Leicester, England
Registered: 2006-02-22
Posts: 10
Website

How to return a category list but without using the cateogry list tag?

Basically I want to populate a select menu with categories.

i.e.

<select> <option>Category 1</option> <option>Category 2</option> <option>Category 3</option> <option>Category 4</option> <option>Category 5</option> </select>

The Textpattern category_list tag returns a list of categories wrapped in anchors, which is useless in this instance.

Any ideas how to return a simple text string or list of categories, using a plugin, php or otherwise?

Many thanks.

Offline

#2 2007-07-05 14:47:01

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

Re: How to return a category list but without using the cateogry list tag?

<select><option><txp:php>
  echo join('</option> <option>', doSpecial(safe_column('title', 'txp_category', '1=1 ORDER BY title ASC')));
</txp:php></option></select>

Last edited by ruud (2007-07-05 14:48:20)

Offline

#3 2007-07-06 12:07:10

kitto
Member
From: Leicester, England
Registered: 2006-02-22
Posts: 10
Website

Re: How to return a category list but without using the cateogry list tag?

Excellent. Thanks Ruud – I’ll give that a go.

Offline

#4 2007-07-08 11:04:35

kitto
Member
From: Leicester, England
Registered: 2006-02-22
Posts: 10
Website

Re: How to return a category list but without using the cateogry list tag?

One further question – I should have mentioned in my first post.

I also need to populate the value of each option with the category title. The above also returns ‘root’ as the final category – any way to leave that out?

E.g. the code Ruud posted returns;

<select><option>Category 1</option><option>Category 2</option><option>root</option></select>

And I need it to return;

<select><option value="Category 1">Category 1</option><option value="Category 2">Category 2</option></select>

Thanks again for any help.

Offline

#5 2007-07-08 23:39:04

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: How to return a category list but without using the cateogry list tag?

<select><option><txp:php>
  echo join('</option> <option>', doSpecial(safe_column('title', 'txp_category', 'name != "root" ORDER BY title ASC')));
</txp:php></option></select>

Last edited by Mary (2007-11-17 07:20:26)

Offline

#6 2007-11-17 06:09:28

mhulse
Plugin Author
From: Eugene Oregon
Registered: 2005-01-21
Posts: 200

Re: How to return a category list but without using the cateogry list tag?

Thanks to ruud and Mary for being so helpful. :)

Last edited by mhulse (2007-11-27 18:38:58)

Offline

Board footer

Powered by FluxBB