我创建了一个自定义的帖子类型“公文包”,如下所示:
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
//\'menu_icon\' => get_stylesheet_directory_uri() . \'/article16.png\',
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => 4,
\'taxonomies\' => array(\'post_tag\',\'category\'),
\'supports\' => array(\'title\',\'editor\',\'comments\',\'trackbacks\',\'revisions\',\'custom-fields\',\'page-attributes\',\'thumbnail\', \'excerpt\', \'tags\')
);
register_post_type( \'portfolio\' , $args );
我还有一些其他自定义字段,其中包含一个操作:
add_action("admin_init", "admin_init");
function admin_init(){ // add_meta_box( $id, $title, $callback, $page, $context, $priority );
add_meta_box("media", "Media Type", "media", "portfolio", "side", "high");
add_meta_box("map_meta", "Mapping Info", "map_meta", "portfolio", "normal", "high");
}
虽然我曾经有过这样的工作,但我不知道如何让它只为这个页面加载脚本。现在我只是把他们和其他人放在一起
wp_enqueue_script
像这样:
function my_init() {
if (!is_admin()) {
....
}
if (is_admin()) {
wp_register_script(\'Gmaps\', \'http://maps.google.com/maps/api/js?sensor=false\', false, \'3.0\', false);
wp_enqueue_script(\'Gmaps\');
wp_register_style(\'admin_js\', get_bloginfo(\'template_directory\') . \'/admin.js\');
wp_enqueue_script(\'admin_js\');
wp_register_script(\'Zmaps\', get_bloginfo(\'template_directory\') .\'/scripts/maps.js\', array(\'Gmaps\'), \'1.0\', true);
wp_enqueue_script(\'Zmaps\');
}
}
add_action(\'wp_enqueue_scripts\', \'my_init\');
但这些对我来说都不重要。如何将这些脚本加载到管理页面?更好的是,如何专门为公文包自定义帖子类型的编辑页面加载它们?