Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

the wordpress admin already uses some kind of toggle on the menu and on metaboxes.. w/ "Click to Toggle" buttons that remember the open versus closed state. Does anybody know what code is responible for this? I'd like to implement it into sections of my custom metaboxs, and it doesn't seem like I should need to add a script to the admin area (b/c it is already slow) when WP has this functionality by default.

share|improve this question

3 Answers 3

Checkout the HTML for a WP meta-box :

<div id="my_div" class="postbox ">
    <div class="handlediv" title="Click to toggle."><br></div>
    <h3 class="hndle"><span>title</span></h3>
    <div class="inside">
        ...
    </div>
</div>

If you follow that structure (and CSS classes) in your custom meta-box, the toggle will work.

share|improve this answer
    
awesome. was clearly over-complicating. borrow their markup and it works automagically. thanks! –  helgatheviking Jun 28 '11 at 15:42
    
do i have to give everything a unique ID? i tried going w/o an id, and it stops working when i have multiple toggles –  helgatheviking Jun 28 '11 at 15:54
    
also- doesn't seem to "remember" the open/closed status –  helgatheviking Jun 28 '11 at 16:01
    
@helgatheviking, my_id should be unique yes. –  mike23 Jun 28 '11 at 16:43

That's bundled together with the current user data (else nothing will be remembered), which you can inspect with my (hardly outdated) "Current User Deamon" Plugin. That's the fields:

// User Meta Arrays:
$metaboxhidden_dashboard    = $current_user->metaboxhidden_dashboard;
$capabilities               = $current_user->{ $wpdb->prefix . 'capabilities' };
$closedpostboxes_page       = $current_user->closedpostboxes_page;
$metaboxhidden_page         = $current_user->metaboxhidden_page;
$autosave_draft_ids         = $current_user->{ $wpdb->prefix . 'autosave_draft_ids' };
$closedpostboxes_post       = $current_user->closedpostboxes_post;
$metaboxhidden_post         = $current_user->metaboxhidden_post;
$metaboxorder_dashboard     = $current_user->{ $wpdb->prefix . 'metaboxorder_dashboard' };
share|improve this answer
    
so if by default it will only remember these particular data i have to use a toggle plugin if i want toggle to work inside my metaboxes? –  helgatheviking Jun 28 '11 at 16:04
    
You can use plain simple jQuery toggle function as JQuery already is loaded in admin. Take a look at the core code if you want your status to be remembered. –  kaiser Jun 28 '11 at 16:18
    
i ended up using plain toggle plus cookies. i'll have to look more closely at core to see if i can eliminate loading another plugin. –  helgatheviking Jul 6 '11 at 15:24

Try this mark-up with nothing else:

<div class="postbox">
<div title="Click to toggle" class="handlediv"><br></div>
<h3 class="hndle">HEADLINE/META BOX TITLE</h3>
<div class="inside">YOUR CONTENT</div>
</div><!-- // postbox -->
share|improve this answer
    
works great while you are on the page. but it doesn't 'remember' the open/closed status from your last visit the way the default metaboxes do. i think b/c as @kaiser says in his response, it only remembers certain meta data –  helgatheviking Jul 9 '11 at 3:19
    
The best and easiest way still is using add_meta_box()... or take a look into core where the closed boxes get set and add it to your script. –  kaiser Jul 10 '11 at 16:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.