尝试插入帖子时,我遇到了自定义添加媒体按钮 wordpress 的问题。当我尝试从 url 插入发布时,图像没有显示(未定义的结果不是 url 图像)但是如果我从媒体库中选择,那么我按“插入发布”它就可以了。
这是我的代码:
jQuery('.upload_image #upload_image_button').click(function() {
formfield = jQuery('#upload_image').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
targetInput = jQuery(this).next('input');
previewImage = jQuery(this).prev('div');
window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
targetInput.val(imgurl);
previewImage.html('<img src="' + imgurl + '" width="100px" height="100px" />');
tb_remove();
}
return false;
});
这是我的html:
<ul class="prev-thumb">
<li class="upload_image">
<div class="preview-image"><?php echo(isset($images[0])) ? '<img src="'.$images[0].'" width="100px" height="100px" />' : ''; ?></div>
<input class="button button-primary button-large" id="upload_image_button" value="Upload Image" type="button" />
<input id="upload_image" size="36" name="item[images][]" type="hidden" />
</li >
<li class="upload_image">
<div class="preview-image"><?php echo(isset($images[1])) ? '<img src="'.$images[1].'" width="100px" height="100px" />' : ''; ?></div>
<input class="button button-primary button-large" id="upload_image_button" value="Upload Image" type="button" />
<input id="upload_image" size="36" name="item[images][]" type="hidden" />
</li >
<li class="upload_image">
<div class="preview-image"><?php echo(isset($images[2])) ? '<img src="'.$images[2].'" width="100px" height="100px" />' : ''; ?></div>
<input class="button button-primary button-large" id="upload_image_button" value="Upload Image" type="button" />
<input id="upload_image" size="36" name="item[images][]" type="hidden" />
</li >
<li class="upload_image">
<div class="preview-image"><?php echo(isset($images[3])) ? '<img src="'.$images[3].'" width="100px" height="100px" />' : ''; ?></div>
<input class="button button-primary button-large" id="upload_image_button" value="Upload Image" type="button" />
<input id="upload_image" size="36" name="item[images][]" type="hidden" />
</li >
</ul>
对不起我的英语,提前谢谢,我是新来的:)