Skip to content
Create a gist now

Instantly share code, notes, and snippets.

WordPressプラグイン内でメディアアップローダーを使用してファイル名を選択しテキストフィールドに挿入する
<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>
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;
});
});
});
<?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');
}
?>
@miya0001
Owner

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

@cloudsben

cool, I like it.

@finzaiko

Thanks for plugin that help to control all code just from gist, sometime I want full write my sentence blog in my markdown file, it is possible add more feature can be embed <!--more--> auto split main front blog

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.