Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2011-02-01 10:19:14

sare
New Member
From: Helsinki
Registered: 2010-09-26
Posts: 7

Re: [howto] Use List of Categories as Values for glz_custom_field Dropdown Options

Hi tye,

just switch ’1=1’ to ‘name != “root”’ to exclude root from the list.

(It’s been 1½ months since you asked but hey. Somebody might care…)

Offline

#12 2011-02-08 05:31:31

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 858
Website

Re: [howto] Use List of Categories as Values for glz_custom_field Dropdown Options

Thanks sare

So in my case I needed to choose only images and exclude root from the list, so came up with this:

$query = safe_rows('name, title', 'txp_category','type like "image" AND name!="root"');

:)

Offline

#13 2011-02-08 09:14:21

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [howto] Use List of Categories as Values for glz_custom_field Dropdown Options

tye wrote:

So in my case I needed to choose only images and exclude root from the list, so came up with this

As you are not taking advantage of LIKE operator and it’s matching abilities, I would recommend to replace it with equal sign (=) to optimize the query :)

Offline

#14 2011-02-08 12:04:16

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 858
Website

Re: [howto] Use List of Categories as Values for glz_custom_field Dropdown Options

Oh yeah – that makes total sense :)

Thanks Jukka :)

Offline

#15 2011-10-08 08:44:58

phuture303
Member
Registered: 2008-09-14
Posts: 127

Re: [howto] Use List of Categories as Values for glz_custom_field Dropdown Options

Hi, I’m using this script:

<?php
function list_categories($custom_field, $custom_id, $custom_value) {
    $categories = array();
	$query = safe_rows('name, title', 'txp_category','type like "image" AND name!="root"');
    foreach ($query as $category)
        $categories[$category['name']] = $category['title'];
    return glz_selectInput($custom_field, $custom_id, $categories, $custom_value, "");
}
?>

It works perfectly, but the image categories are shown in a strange order (see this screenshot), i would like to have them sorted alphabetically. Any chances?

Many thanks!

David

Offline

#16 2011-10-08 10:16:15

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,588
Website

Re: [howto] Use List of Categories as Values for glz_custom_field Dropdown Options

alter line 4 as follows:

$query = safe_rows('name, title', 'txp_category','type="image" AND name!="root" ORDER BY name');

or use title instead of name if you prefer to sort by the title. As jukka mentioned above, you can use an equals sign instead of like.


TXP Builders – finely-crafted code, design and txp

Offline

#17 2011-10-08 10:20:25

phuture303
Member
Registered: 2008-09-14
Posts: 127

Re: [howto] Use List of Categories as Values for glz_custom_field Dropdown Options

Hi Jakob,

perfect – thank you very much!

:-D

Offline

#18 2012-03-22 00:33:27

floodfish
Member
From: Brooklyn, NY
Registered: 2007-01-11
Posts: 155
Website

Re: [howto] Use List of Categories as Values for glz_custom_field Dropdown Options

This is just wonderful. Thanks, Kevin!

Offline

#19 2013-11-26 18:05:26

gfdesign
Member
From: Argentina
Registered: 2009-04-20
Posts: 401

Re: [howto] Use List of Categories as Values for glz_custom_field Dropdown Options

Sorry if I post my consultation here too, but it’s related to this topic in some way.

I have an issue with a custom field created with glz_custom_field. This field is based on a custom script (such as this topic explains us, similar to my_images.php script that glz_custom_field brings as example).

With this new custom field, I no have any control using “bot_write_tab_customize” to hide or arrange to other position. It would seem this issue is due to just “glz_custom_field_script” fields.

I just want to ask if somebody does have the same problem?
I look forward your comments
Best regards

P/d: I already posted this question into bot_write_tab_customize forum, but I haven’t recieved answer (up to now)

Offline

Board footer

Powered by FluxBB