Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

rdcravens on "Main Menu -> Dynamic Select Box -> Need Ideas"

$
0
0

OK, so I have what seems to be a unique issue until I ask it and then find the list of answers I could not find for a week :-)

I have a select box on a page, lets call it the fruit selection box. This box updates the page (posts to self) to change the content based on the fruit selected. It also writes to the DB so that the site can remember what fruit you last looked at the next time you visit (so it passes variables - not just a page changer).

The list of fruits is created by the user and stored. The user can store up to 20 different fruits and each fruit possibility has its own column in the users table (for a reason) - so 20 potential columns with data coming in and one select box.

$change_list = htmlentities($_REQUEST['which_list']);

if ($change_list)
{
	$update = $wpdb->update('wp_users', array('active_list' => $change_list), array('ID' => $user_id), array('%f'));
	if ( is_wp_error( $update ) ) { echo 'Error Updating Active List'; }
}

if ($change_list)
{
	$which_list = $change_list;
} else {
	$which_list = $current_user->active_list;
}

// ------------ Create our drop down list selector
                      echo '<td style="width:80%; text-align:left;"><form name="whichlist" action="" method="POST"><select style="cursor:pointer; border:0px; outline:0px;" name="which_list" onChange="document.whichlist.submit()">';
$i = 1;
while ($i <= 20)
{
  $sel = '';
  $list_name = $current_user->{'fruit' . $i . '_name'};
  if ($which_list == $i){ $sel = 'selected'; }
  if ($list_name) { echo '<option value="' . $i . '" '. $sel .'>' . $list_name . '</option>'; }
  $i++;
}
echo '</select></form></td>';
// ------------ End Selector

All is fine and dandy to this point (works like a champ)... Now the tricky part (the part I can not solve)...

I would like the dynamically generated select list to be added to the navigation menu as a drop down select box like it would be seen on the page it is on now (drop down arrow, shows selected item on the list)...

I do not want to dynamically create a whole menu system, just add one top level menu item to the existing menu when the page opens (every time). I prefer to replace a menu placeholder so that I can move it around the menu as needed using the menu interface.

Is this possible? I am using the standard WP Menu system.


Viewing all articles
Browse latest Browse all 8245

Trending Articles