想要在 wordpress 的插件页面中制作可拖动和可排序的部分,就像我们在仪表板上看到的那样。我试图找到但力求得到我想要的。这是一段代码,虽然它添加了两个 div,其界面类似于仪表板中的可拖动界面,但我无法拖动。
<div class="wrap">
<h2>I like to move it, move it</h2>
<div class="meta-box-sortables ui-sortable">
<div class="postbox" id="p1">
<h3 class="hndle">Drag me around, babe</h3>
<div class="container">
<p>Your content goes here</p>
</div>
</div><!-- .postbox -->
<div class="postbox" id="p2">
<h3 class="hndle">Drag me, too</h3>
<div class="container">
<p>Your content goes here, again</p>
</div>
</div><!-- .postbox -->
</div><!-- .meta-box-sortables.ui-sortable-->
</div><!-- .wrap -->
<?php
function move_me_around_scripts() {
wp_enqueue_script('dashboard');
wp_enqueue_script( 'jquery-ui-sortable');
}
function admin_page_with_draggable_boxes(){
$my_page = add_dashboard_page( 'moveit', 'moveit', 'read',
'moveit' );
add_action('load-'.$my_page, 'move_me_around_scripts');
}
add_action('admin_menu', 'admin_page_with_draggable_boxes'); ?>