2017-06-28 9 views
0

WordPress用のCMB2を使用してカスタムフィールドをセットアップしようとしています。これまでの単純なテキストフィールドと同様にイメージも機能しますが、複数のファイルフィールドを使用して1つのイメージを読み込むには2分かかります。CMB2の画像読み込み速度が遅い

これは私がそれを使用する方法です:

のfunctions.php

function cmb2_metaboxes() { 

$prefix = '_npport_'; 

$cmb->add_field(array(
    'name' => 'Test File List', 
    'desc' => '', 
    'id' => 'wiki_test_file_list', 
    'type' => 'file_list', 
    // 'preview_size' => array(100, 100), // Default: array(50, 50) 
    // 'query_args' => array('type' => 'image'), // Only images attachment 
    // Optional, override default text strings 
    'text' => array(
     'add_upload_files_text' => 'Replacement', // default: "Add or Upload Files" 
     'remove_image_text' => 'Replacement', // default: "Remove Image" 
     'file_text' => 'Replacement', // default: "File:" 
     'file_download_text' => 'Replacement', // default: "Download" 
     'remove_text' => 'Replacement', // default: "Remove" 
    ), 
)); 
} 

単一のビューの表示内容

function cmb2_output_file_list($file_list_meta_key, $img_size = 'medium') { 

       // Get the list of files 
       $files = get_post_meta(get_the_ID(), $file_list_meta_key, 1); 

       echo '<div class="file-list-wrap">'; 
       // Loop through them and output an image 
       foreach ((array) $files as $attachment_id => $attachment_url) { 
        echo '<div class="file-list-image">'; 
        echo wp_get_attachment_image($attachment_id, $img_size); 
        echo '</div>'; 
       } 
       echo '</div>'; 
      }; 
      cmb2_output_file_list('wiki_test_file_list', 'small'); 

私はコードで何かが間違っている必要があります推測しますしかし、私は本当に何が分かりません。デモ用リンク:link

答えて

0

私は試してみましたが、全く問題ありません。

$filesをチェックしてください。偶然にも多くのアイテムを'add_upload_files_text'に挿入したと思われます。

関連する問題