[wp-hackers] Sidebar widget HTML/DOM

ravi ravi-lists at g8o.net
Thu Jun 24 18:50:46 UTC 2010


Scribu,

I am trying to make the widget contents collapsible, with hide/show triggered by clicking on the title.

Otto:

On Jun 24, 2010, at 11:36 AM, Otto wrote:
> On Thu, Jun 24, 2010 at 9:38 AM, [ ravi ] <ravi-lists at g8o.net> wrote:
>> FYI, the jQuery hack I have is to first use ‘before_title’ to add an <h2> element with class=‘widgettitle’ to each element that has a title. This gives me something like this in the sidebar (using the Pages widget as an example):
>> 
>> <div class=‘widget ….’ ….>
>>        <h2 class=‘widgettitle’ ….>Pages</h2>
>>        <ul>
>>                <li> … page1 … </li>
>>                <li> … page2 … </li>
>>        </ul>
>> </div>
>> 
>> Since I want to wrap the UL (in this example) in a DIV so I can style it (make it collapsible, actually, in my case), here’s what I do in jQuery:
>> 
>>   jQuery('.widgettitle').each(
>>       function()
>>       {
>>           jQuery(this).nextAll().wrapAll('<div class="widgetcontent" />’);
>>       }
>>   );
>> 
>> This works for me, for now, but it would still be nice to be able to wrap it explicitly/deterministically in PHP, so if anyone has any ideas, including filters/actions that would accomplish this on the server end, please do let me know.
> 
> Why do you need to wrap it in a div? It's directly addressable with
> jQuery(".widget ul") if you want to do it that way.


Otto, I am not sure each widget will have a UL. For e.g the text widget does not, I think. This may be the case for custom/plug-in inserted widgets as well.

	—ravi




More information about the wp-hackers mailing list