1 tilqicom Dec 12, 2010 15:14
3 tilqicom Jan 07, 2011 22:01
sam2kb wrote:
So all you want is display a dropdown of main cats and a multiple-select list of sub-cats, is that correct?
basically all i need is a "dropdown" and a "multiple select" for all categories.. store and retrieve them in array in DB in order to use in the above jquery code.
For example, when i post something about "Albert Einstein" as a "main category" (radio), i have to select "Scientist" and "German" categories as "extra category" too. To get rid of this selection each time, i want to associate them once and for all.
4 sam2kb Feb 22, 2011 13:25
Here's the meat of this plugin. You still need to add some js
global $DB;
$blog = 1; // set a working blog here
$main_cats = $DB->get_results('SELECT cat_ID, cat_name FROM T_categories
WHERE cat_blog_ID = '.$DB->quote($blog).'
AND cat_parent_ID IS NULL');
$extra_cats = $DB->get_results('SELECT cat_ID, cat_name, cat_parent_ID FROM T_categories
WHERE cat_blog_ID = '.$DB->quote($blog).'
AND cat_parent_ID IS NOT NULL');
$Form = & new Form( 'admin.php', '', 'post' );
$Form->begin_form( 'fform' );
$Form->hidden_ctrl();
$Form->hiddens_by_key( get_memorized() );
$Form->begin_fieldset($this->name);
if( !empty($main_cats) )
{ // Build a dropdown
$Form->select_input_options( 'qqq', $this->get_options($main_cats), '', '' );
}
if( !empty($main_cats) )
{ // Build multiple-select menu
$Form->select_input_options( 'www', $this->get_options($extra_cats), '', '', array('multiple'=>'multiple') );
}
$Form->end_fieldset();
$Form->end_form( array( array( 'value' => 'Whatever' ) ) );
function get_options( $rows )
{ // Build options list
$r = '';
foreach( $rows as $row )
{
$r .= '<option ';
if( isset($row->cat_parent_ID) )
{
$r .= 'id="parentID-'.$row->cat_parent_ID.'" ';
}
$r .= 'value="'.$row->cat_ID.'">'.$row->cat_name.'</option>';
}
return $r;
}
5 tilqicom Feb 22, 2011 13:47
thank you very much.. let me see if i can make this into a plugin.shall it succeed, i ll post back here.
So all you want is display a dropdown of main cats and a multiple-select list of sub-cats, is that correct?