除了默认可用的特色图像之外,我想在post editor区域的元框中添加多个特色图像。
我已经添加了元框,但我不知道如何添加特色图像功能。
function another_image_custom_meta() {
    add_meta_box(\'another_meta\', __(\'Another Image\'), \'another_image_callback\', \'another\',\'side\');
}
add_action(\'add_meta_boxes\', \'another_image_custom_meta\');
 其中第四个字段中的另一个字段是我的自定义帖子类型。
function another_image_callback($post) {
    wp_nonce_field(basename(__FILE__), \'another_nonce\');
    $p_stored_meta = get_post_meta($post->ID);
    ?>
    <p>
       Another featured image
    </p>
    <?php
}
 上面的函数运行良好,它显示了元框。
如何添加带有图片上传的链接,并将其作为特色图片保存到相应的帖子中。像默认的特色图片一样,我希望这里有相同的功能。有人能帮忙吗?
 
                SO网友:helgatheviking
                我知道您说过您正在寻找自己的实现,但添加多个特色图像元盒的最简单方法是使用Multiple Post Thumbnail plugin.
根据插件的文档,定义辅助框的方法是将此代码添加到主题的函数中。php
   if (class_exists(\'MultiPostThumbnails\')) {
        new MultiPostThumbnails(
            array(
                \'label\' => \'Secondary Image\',
                \'id\' => \'secondary-image\',
                \'post_type\' => \'post\'
            )
        );
    }
 然后在主题中的某个位置显示图像:
if (class_exists(\'MultiPostThumbnails\')) : MultiPostThumbnails::the_post_thumbnail(get_post_type(), \'secondary-image\'); endif;