您的位置:首页 > 其它

黄聪:如何在wordpress任何一个页面调用“插入图片”按钮,实现上传图片功能

2014-09-23 10:40 956 查看
<?php
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_enqueue_script('my-upload');
wp_enqueue_style('thickbox');
?>
<input id="upload_image" type="text" value="" />
<input id="upload_image_button" type="button" style="width:auto;height:20px;" value="上传图片" />
<script>
jQuery(document).ready(function() {
jQuery('#upload_image_button').click(function() {
formfield = jQuery('#upload_image').attr('name');
// show Wordpress' uploader modal box
tb_show('', '<?php echo admin_url(); ?>media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
// this will execute automatically when a image uploaded and then clicked to 'insert to post' button
imgurl = jQuery('img',html).attr('src');
// put uploaded image's url to #upload_image
jQuery('#upload_image').val(imgurl);
tb_remove();
}
});
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐