我已经创建了一个自定义帖子类型,在该帖子类型的管理页面上,我希望显示一个图像,可以作为用户上传图像的指南。是否有一个函数,我可以使用它将一个图像插入到管理员的自定义帖子类型中。(我曾尝试在谷歌上搜索,但所有结果似乎都与上传图像有关)。
向自定义帖子类型管理页面添加“指南”图像
3 个回复
最合适的回答,由SO网友:Overdose 整理而成
你可以加一个custom help
简单示例摘自here
function mqw_example_contextual_help( $contextual_help, $screen_id) {
# Uncomment this to see actual screen
# echo \'Screen ID = \'.$screen_id.\'<br />\';
switch( $screen_id ) {
case \'mycustompostname\' : //Your custom post name
//Just to modify text of first tab
$contextual_help .= \'<p>\';
$contextual_help = __( \'Your text here and the image after.\' );
$contextual_help .= \'</p>\';
break;
}
return $contextual_help;
}
add_filter(\'contextual_help\', \'mqw_example_contextual_help\', 10, 2);
SO网友:mrwweb
您还可以考虑使用edit_form_after_title
3.5中介绍的操作introduction post 为此,以及edit_form_after_editor
.
我认为您需要仔细考虑UI,并使图像能够隐藏(因此这可能不是处理它的最佳方式,但我确实认为这些钩子有时是上下文帮助的合适钩子(尽管add_help_tab
其位置如@t-f所说)。
SO网友:tfrommen
你知道WP指针的概念吗?
下面是一个在仪表板上引入指针的简短示例。
PHP将其放入functions.php
如果您在主题中定义了CPT,或者如果您在其中定义了CPT,则将其放入插件中:
add_action(\'admin_enqueue_scripts\', \'my_pointer_load\', 1000);
function my_pointer_load($hook_suffix) {
// Don\'t run on WP < 3.3
if (get_bloginfo(\'version\') < \'3.3\') return;
$screen = get_current_screen();
$screen_id = $screen->id;
$pointers = apply_filters(\'my_admin_pointers-\'.$screen_id, array());
if (! $pointers || ! is_array($pointers)) return;
// Get dismissed pointers
$dismissed = explode(\',\', (string) get_user_meta(get_current_user_id(),
\'dismissed_wp_pointers\', true));
$valid_pointers = array();
// Check pointers and remove dismissed ones.
foreach ($pointers as $pointer_id => $pointer) {
// Sanity check
if (in_array($pointer_id, $dismissed)
|| empty($pointer)
|| empty($pointer_id)
|| empty($pointer[\'target\'])
|| empty($pointer[\'options\'])
)
continue;
$pointer[\'pointer_id\'] = $pointer_id;
// Add the pointer to $valid_pointers array
$valid_pointers[\'pointers\'][] = $pointer;
}
// No valid pointers? Stop here.
if (empty($valid_pointers)) return;
wp_enqueue_style(\'wp-pointer\');
wp_enqueue_script(
\'my-wp-pointer\',
// For a plugin use plugins_url(\'js/my-wp-pointer.js\', __FILE__)
get_stylesheet_directory_uri().\'/js/my-wp-pointer.js\',
array(\'wp-pointer\')
);
wp_localize_script(\'my-wp-pointer\', \'myWPPointer\', $valid_pointers);
}
// Let\'s add a pointer to the dashboard
add_filter(\'my_admin_pointers-dashboard\', \'my_register_pointer\');
function my_register_pointer($p) {
$p[\'some_pointer_id\'] = array(
// What element do you want to explain?
// Use class (e.g., \'.wrap\') or ID (e.g., \'#dashboard_right_now\')
\'target\' => \'.wrap\',
\'options\' => array(
\'content\' => "<h3>Title</h3><p>What is it that you\'d like to tell?</p>",
\'position\' => array(
\'edge\' => \'top\',
\'align\' => \'middle\',
)
)
);
return $p;
}
如果您想要一个有点烦人和粘人的指针,请从上面删除已解除的代码my_pointer_load
作用JavaScript将以下内容放入/js/my-wp-pointer.js
文件(或其他地方)并调整上述内容wp_enqueue_script
):
jQuery(document).ready(function($) {
my_open_pointer(0);
function my_open_pointer(i) {
pointer = myWPPointer.pointers[i];
options = $.extend(pointer.options, {
close: function() {
$.post(ajaxurl, {
pointer: pointer.pointer_id,
action: \'dismiss-wp-pointer\'
});
}
});
$(pointer.target).pointer(options).pointer(\'open\');
}
});
Note: 此答案基于this tutorial.结束