Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

WordPressプラグイン内でメディアアップローダーを使用してファイル名を選択しテキストフィールドに挿入する

View select_media.html
1 2 3 4 5 6 7
<h3>My Picture (1)</h3>
<input type="text" id="my_media_1" name="my_media_1" value="" />
<a class="media-upload" href="JavaScript:void(0);" rel="my_media_1">Select File</a>
 
<h3>My Picture (2)</h3>
<input type="text" id="my_media_2" name="my_media_2" value="" />
<a class="media-upload" href="JavaScript:void(0);" rel="my_media_2">Select File</a>
View select_media.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
jQuery('document').ready(function(){
jQuery('.media-upload').each(function(){
var rel = jQuery(this).attr("rel");
jQuery(this).click(function(){
window.send_to_editor = function(html) {
imgurl = jQuery('img', html).attr('src');
jQuery('#'+rel).val(imgurl);
tb_remove();
}
formfield = jQuery('#'+rel).attr('name');
tb_show(null, 'media-upload.php?post_id=0&type=image&TB_iframe=true');
return false;
});
});
});
View select_media.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php
add_action('admin_print_scripts-'.$hook_suffix, 'my_admin_scripts');
add_action('admin_print_styles-'.$hook_suffix, 'my_admin_styles');
function my_admin_styles() {
wp_enqueue_style('thickbox');
}
function my_admin_scripts() {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_enqueue_script('jquery');
}
?>
Owner

詳細は以下のページで。
http://firegoby.theta.ne.jp/archives/2261

cool, I like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.