这other Stack Overflow question正是我所需要的,但答案就是link已过时5年了。
它告诉我更改以下代码:
public function enqueue_admin_scripts() {
wp_enqueue_script("featured-image-custom", plugins_url(basename(dirname(__FILE__)) . '/js/multi-post-thumbnails-admin.js'), array('jquery'));
}
到此:
public function enqueue_admin_scripts() {
$template_url = get_bloginfo('template_url') . '/js/multi-post-thumbnails-admin.js';
wp_enqueue_script("featured-image-custom", $template_url, array('jquery'));
}
但更新的插件现在改为:
public function enqueue_admin_scripts( $hook ) {
global $wp_version, $post_ID;
// only load on select pages
if ( ! in_array( $hook, array( 'post-new.php', 'post.php', 'media-upload-popup' ) ) )
return;
if (version_compare($wp_version, '3.5', '<')) {
add_thickbox();
wp_enqueue_script( "mpt-featured-image", $this->plugins_url( 'js/multi-post-thumbnails-admin.js', __FILE__ ), array( 'jquery', 'media-upload' ) );
} else { // 3.5+ media modal
wp_enqueue_media( array( 'post' => ( $post_ID ? $post_ID : null ) ) );
wp_enqueue_script( "mpt-featured-image", $this->plugins_url( 'js/multi-post-thumbnails-admin.js', __FILE__ ), array( 'jquery', 'set-post-thumbnail' ) );
wp_enqueue_script( "mpt-featured-image-modal", $this->plugins_url( 'js/media-modal.js', __FILE__ ), array( 'jquery', 'media-models' ) );
}
wp_enqueue_style( "mpt-admin-css", $this->plugins_url( 'css/multi-post-thumbnails-admin.css', __FILE__ ) );
}
我已经尝试将其保留原样,如博客链接所示更改所有内容,并且每次添加$ template_url变量都是$ this。在WordPress的后端,我看到第二个特色图像,但它唯一能做的就是在编辑器的URL中添加一个数字符号(#)。
这里还有我的代码添加到functions.php文件中:
// Load external file to add support for MultiPostThumbnails. Allows you to set more than one "feature image" per post.
require_once('library/multi-post-thumbnails.php');
// Define additional "post thumbnails". Relies on MultiPostThumbnails to work
if (class_exists('MultiPostThumbnails')) {
new MultiPostThumbnails(array(
'label' => '2nd Feature Image',
'id' => 'feature-image-2',
'post_type' => 'page'
)
);
new MultiPostThumbnails(array(
'label' => '3rd Feature Image',
'id' => 'feature-image-3',
'post_type' => 'home'
)
);
};
请感谢你的时间。