SORU
12 Aralık 2012, ÇARŞAMBA


3.5 özel medya tema seçenekleri için upload Wordpress

wordpress 3.5 yakın zamanda serbest bırakıldı, thickbox ve pencere ile wordpress medya yükleme sistemi kullandım.benim wordpress tema (arka plan, logo vb...) bazı seçenekler için send_to_editor.

Ama wordpress Yeni Medya Yöneticisi entegre var bildiğiniz gibi, özel alanlar olarak dosya/resim yüklemek için bu yeni özellik kullanılır istedim. Sabah ve istediği sonucu almak için bir yol bulmak için harcadım.

Bazılarınız için yararlı olabilir bu çözümü buldum. Bana kodu ile ilgili görüşleriniz ve aklınızda herhangi bir yenilik vermek için teşekkürler !

Örnek HTML

<a href="#" class="custom_media_upload">Upload</a>
<img class="custom_media_image" src="" />
<input class="custom_media_url" type="text" name="attachment_url" value="">
<input class="custom_media_id" type="text" name="attachment_id" value="">

jQuery Kod :

$('.custom_media_upload').click(function() {

    var send_attachment_bkp = wp.media.editor.send.attachment;

    wp.media.editor.send.attachment = function(props, attachment) {

        $('.custom_media_image').attr('src', attachment.url);
        $('.custom_media_url').val(attachment.url);
        $('.custom_media_id').val(attachment.id);

        wp.media.editor.send.attachment = send_attachment_bkp;
    }

    wp.media.editor.open();

    return false;       
});

Eğer her ayarları "Eki değişken" bir konsol yap.yer görmek isterseniz(eklenti) (eklenti) günlük uyarı.

İyi günler !

CEVAP
17 NİSAN 2013, ÇARŞAMBA


Tesadüfi bir şekilde bu konuda gidiyorum. Javascript kodu büyük ihtimalle böyle bir şey görünmelidir

$('.custom_media_upload').click(function(e) {
    e.preventDefault();

    var custom_uploader = wp.media({
        title: 'Custom Title',
        button: {
            text: 'Custom Button Text'
        },
        multiple: false  // Set this to true to allow multiple files to be selected
    })
    .on('select', function() {
        var attachment = custom_uploader.state().get('selection').first().toJSON();
        $('.custom_media_image').attr('src', attachment.url);
        $('.custom_media_url').val(attachment.url);
        $('.custom_media_id').val(attachment.id);
    })
    .open();
});

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Christopher Bill

    Christopher

    30 NİSAN 2009
  • Elliot Davin

    Elliot Davin

    28 Kasım 2008
  • Greater Than Gatsby Photoshop Actions & Lightroom Presets

    Greater Than

    11 ŞUBAT 2013