Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-11-27 17:59:43

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

use a section/category select list in a custom pref

Hi, I’m setting custom prefs for a Txp theme and I would like to know if there is a function I could use to display a section or a link category select list instead of simple inputs… Something like gmtoffset_select which is used to list gmt areas but to list sections or categories. Thx!

Last edited by NicolasGraph (2015-11-27 18:51:12)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#2 2015-11-27 19:02:41

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

Re: use a section/category select list in a custom pref

tye recently mentioned this menu for the glz-plugin


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

Offline

#3 2015-11-27 20:15:44

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: use a section/category select list in a custom pref

uli wrote #296873:

tye recently mentioned this menu for the glz-plugin

Thanks, it looks interesting. I’ll see how hard is it to do and decide to work on it or keep text inputs… In fact I was wondering if there would be a way to use existing functions like section_select_list, but I’m maybe to lazy. :)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#4 2015-11-27 22:36:31

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: use a section/category select list in a custom pref

I can display a section select list for a custom pref by adding this function…

function section_select_list($name, $val)
{
    $sections = safe_rows("name, title", 'txp_section', "name != 'default' ORDER BY title, name");
    $vals = array();
    foreach ($sections as $row) {
        $vals[$row['name']] = $row['title'];
    }
    return selectInput($name, $vals, $val, '', '', $name);
}

…to txp.prefs.php and adding section_select_list as html pref type, but how could I include this kind of function in a plugin instead of txp.prefs.php to make it possible to access it in the same way?

Edit: That was what I needed: register_callback('section_select_list', 'prefs', 'advanced_prefs');; a callback… One more useful thing learnt.

Last edited by NicolasGraph (2015-11-28 17:48:10)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#5 2015-11-28 14:50:41

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: use a section/category select list in a custom pref

So… Now I’m looking for a way to use treeSelectInput instead of selectInput for categories.
I’m not sure how to do it from the following code; each time I tried I got errors:

function category_select_list($name, $val)
{
    $categories = safe_rows("name, title", 'txp_category', "type like 'link'");
    $vals = array();
    foreach ($categories as $row) {
        $vals[$row['name']] = $row['title'];
    }
    return SelectInput($name, $vals, $val, 'true', '', $name);
}

Any help welcome.

Edit: Solved; here it is…

function category_select_list($name, $val) {
    $rs = getTree('root', 'link');
    return treeSelectInput($name, $rs, $val, 35);
}

Last edited by NicolasGraph (2015-11-28 20:07:36)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

Board footer

Powered by FluxBB