Make WordPress Core

Opened 14 years ago

Closed 9 years ago

#13019 closed defect (bug) (fixed)

Allow multiple category widget dropdowns

Reported by: t31os_'s profile t31os_ Owned by: azaozz's profile azaozz
Milestone: 4.2 Priority: low
Severity: minor Version: 3.0
Component: Widgets Keywords: has-patch needs-testing
Focuses: Cc:


Although this may be a somewhat trivial and silly use of category widgets, currently placing two category widgets onto the same page with the dropdown option set results in having duplicate javascript and duplicative identified select boxes.

Whilst the instance of each widget is unique, the select boxes displayed at not given unique IDs or Names, resulting in valid markup, and resulting in only the secondary select box operating correctly. The JS var gets redeclared by the duplicative script, which gives precedence to the second dropdown.

One use case would be a page that lists long archives and shows a jump menu at both the top and bottom of the page. This would have to be done directly in the template due to the widget restrictions at present.

I am attaching a patch that adds a static counter into the category widget function, and gives each dropdown a unique identifier ID/Name, allowing simultaneous use of several category dropdowns, the JS function is updated appropriately to.

Code tested on IE7 and FF3, functionality remains the same as the original code, minus the limitation mentioned above.

Feedback is appreciated, and please do re-tag if necessary.

Attachments (3)

multiple_category_jumpmenus.patch (1.7 KB) - added by t31os_ 14 years ago.
Adds counter to allow simultaneous use of category widget dropdown jump menus
multiple_category_jumpmenus2.patch (1.4 KB) - added by t31os_ 14 years ago.
Using parent class $number va for counter
multiple-category-dropdowns.patch (1.2 KB) - added by froman118 14 years ago.
output JS function only once, pass in unique dropdown ID

Download all attachments as: .zip

Change History (11)

14 years ago

Adds counter to allow simultaneous use of category widget dropdown jump menus

#1 @t31os_
14 years ago

  • Milestone changed from 3.1 to Unassigned

Not sure 3.1 milestone was appropriate, simple patch/enhancement, changed Milestone to Unassigned, to let you folks decide when it's relevant for.

#2 @petervanderdoes
14 years ago

Instead of the static counter use $this->number

Defined in the WP_Widget class:
var $number = false; Unique ID number of the current instance.

14 years ago

Using parent class $number va for counter

#3 @t31os_
14 years ago

My silly typo aside, i've attached a patch using the $number var for the counter as suggested.

#4 @nacin
14 years ago

  • Milestone changed from Awaiting Review to Future Release

Instead of spitting out the same JS multiple times, I'm wondering if this would be a better take:

  • One JS function, takes one argument, the ID of the dropdown.
  • static variable in widget() keeps track of how many times it's been called. If more than once, the JS function is not reprinted, and only the function call and event assignment is.

#5 @t31os_
14 years ago

Would welcome a new patch..

I like the idea, using a function that accepts the ID of the dropdown..

+1 if anyone wants to provide a patch to do just that.. (JS is not my strongest area)..

#6 @froman118
14 years ago

Didn't see this ticket and submitted a duplicate of this last night. Patch is attached that changes the function to accept a dropdown ID and only output the JS function once using a static counter inside widget(). Used the widget ID as part of the dropdown ID so uniqueness is absolutely ensured.

Tested in IE 7, Firefox and Chrome.

14 years ago

output JS function only once, pass in unique dropdown ID

#7 @chriscct7
10 years ago

  • Type changed from enhancement to defect (bug)

Technically since it doesn't work, which given that WordPress lets you add multiple of them to the same page, that's a bug. Reclassifying.

#8 @wonderboymusic
9 years ago

  • Milestone changed from Future Release to 4.2
  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.