我想在后期编辑面板中添加一个由jquery datepicker ui设置的自定义字段。我是wordpress的新手,所以我不知道如何添加这样的内容。我在插件方面运气不好,所以我想知道如何手动添加这样的东西。我熟悉PHP。
在后期编辑中将jQuery Datepicker添加到自定义字段
3 个回复
最合适的回答,由SO网友:Bainternet 整理而成
由于您是WordPress的新手,我建议您使用Meta Box Script for WordPress 它提供了一种将自定义字段添加到后期编辑面板的简单方法,其主要功能包括:
支持各种字段类型,包括:文本、文本区域、复选框、复选框列表、单选框、选择、所见即所得、文件、图像、日期、时间、颜色。开发人员可以通过扩展脚本轻松添加更多类型
SO网友:Scott
我知道你已经接受了一个答案,但我补充说,其他可能更高级的人正在创建自己的元框。下面是我在最近的一个项目中使用的代码,用于在自定义帖子类型的字段上启用日期选择器。请根据您的需要随时修改:
函数文件:
// Register datepicker ui for properties
function admin_homes_for_sale_javascript(){
global $post;
if($post->post_type == \'homes-for-sale\' && is_admin()) {
wp_enqueue_script(\'jquery-ui-datepicker\', WP_CONTENT_URL . \'/themes/philosophy/js/jquery-ui-datepicker.min.js\');
}
}
add_action(\'admin_print_scripts\', \'admin_homes_for_sale_javascript\');
// Register ui styles for properties
function admin_homes_for_sale_styles(){
global $post;
if($post->post_type == \'homes-for-sale\' && is_admin()) {
wp_enqueue_style(\'jquery-ui\', WP_CONTENT_URL . \'/themes/philosophy/css/jquery-ui-1.8.11.custom.css\');
}
}
add_action(\'admin_print_styles\', \'admin_homes_for_sale_styles\');
然后,使用包含日期选择器的元框内联编码:<script>jQuery(document).ready(function(){jQuery( "input[name=\'chb_homes_for_sale_specifics_dateavail\']" ).datepicker({ dateFormat: \'DD, d MM, yy\', numberOfMonths: 3 }); jQuery( "#ui-datepicker-div" ).hide();});</script>
SO网友:kaiser
WordPress 3.5+
您现在只需使用wp_enqueue_script( \'jquery-ui-datepicker\' );
因为它与核心捆绑在一起。结束