原来的 URL 已经失效了,我用SelectBoxIt 进行了测试。以下示例创建了一个管理菜单,其中显示了样式化的类别下拉菜单。关键细节是加载 jQuery 插件,添加捆绑的 WordPress 脚本作为依赖项,请参阅Don't dequeue WordPress jQuery。
文件wp-content/plugins/my-plugin/styled-dropdown.php:
<?php
/* Plugin Name: Styled Dropdown */
add_action( 'admin_menu', 'add_menu_so_3216591' );
function add_menu_so_3216591()
{
add_menu_page(
'SI',
'<span style="color:#e57300;">SelectIt</span>',
'edit_pages',
'so-3216591',
'menu_page_so_3216591',
'', // icon default for empty
1 // create before Dashboard menu item
);
}
function menu_page_so_3216591()
{
wp_enqueue_style(
'select-it',
'http://cdnjs.cloudflare.com/ajax/libs/jquery.selectboxit/3.7.0/jquery.selectBoxIt.css'
);
wp_enqueue_style(
'jquery-ui',
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/base/jquery-ui.css'
);
# Will be used as dependency bellow
wp_register_script(
'select-it',
'http://cdnjs.cloudflare.com/ajax/libs/jquery.selectboxit/3.7.0/jquery.selectBoxIt.min.js'
);
# Main script and dependencies
wp_enqueue_script(
'do-it',
plugins_url( '/js/', __FILE__ ) . 'do-it.js',
array( 'jquery', 'jquery-ui-widget', 'select-it' ) // Dependencies: using bundled WordPress scripts (highly recommended)
);
?>
<div id="icon-post" class="icon32"></div>
<h2>Testing Select Box It</h2>
<p><?php wp_dropdown_categories( array( 'id'=>'select-it-dd' ) ); ?></p>
<?php
}
还有文件wp-content/plugins/my-plugin/js/do-it.js:
jQuery(document).ready(function($)
{
$("#select-it-dd").selectBoxIt(
{
theme: "jqueryui"
});
});