0

プラグインまたは別の方法はありますか...基本的に、ワードプレスのバックエンドで、ユーザーがドロップダウンリストからファイルまたはページを選択できるようにしてから、URLを表示して、簡単にリンクできるようにコピーして貼り付けることができるようにします?

例:

they select a file
    document.pdf
and in a box below it displays the URL
    /wp-content/uploads/2013/10/document.pdf

その URL をコピーしてコンテンツに貼り付けることができますか? これを理解するためにしばらく探していましたが、まだ運がありません!

これが役立つ場合、高度なカスタム フィールドも使用していますか?

//================================== 解決済み ============ =========================// このコードは、選択フィールド (#acf-field-select_content) の ID を取得し、現在の値を取得します選択したオプション。次に、値をテキスト フィールド (#acf-field-show_content_url) に配置しますが、ID の前に「SERVER_NAME」と、Wordpress のデフォルトのパーマリンク オプションである「?p=」をエコーし​​ます。この方法では残念ながらリンクしません。ファイルに直接アクセスしますが、この場合はそれほど大きな問題ではない添付ページに移動します

$serverName = $_SERVER['SERVER_NAME']; 
?>
<script>  
    jQuery(document).ready(function () {
        jQuery("#acf-field-select_content").change(function() {
            var str = "http://<?php echo $serverName; ?>/?p=";
            jQuery("option:selected", this).each(function() {
                str += jQuery(this).val();
            });
            jQuery("#acf-field-show_content_url").val(str);
        })
        .trigger("change");
    });
</script>
<?php }
add_filter('admin_head', 'add_admin_code');
4

2 に答える 2

0

このようなものには、間違いなく Advanced Custom Fields を使用できます。「ファイルアップロード」タイプのフィールドを作成できます。「リピーター」の有料アドオンもあるといいですね。リピーターを使用すると、アップロードされたファイルごとに個別のフィールドを作成する必要なく、繰り返し可能なファイルのリストを作成できます。

見てみな!ACF Repeater Add-on [リンク] .

ただし、プラグインを使用しない場合は、アップロードされたファイルごとに個別のフィールドを作成し、次のようにする必要があります。

<?php
 // Get file url and title
 $uploaded_file_1 = get_field('uploaded_file_1');
 $uploaded_file_1_url = wp_get_attachment_url( $uploaded_file_1 );
 $uploaded_file_1_title = get_the_title( $uploaded_file_1 );
?>

<!-- create dropdown with list of file names and urls -->
<select id="files">
    <option value="">
        Select a file
    </option>
    <option value="<?php echo $uploaded_file_1_url; ?>">
        <?php echo $uploaded_file_1_title; ?>
    </option>
</select>

 <input type="text" id="file-info">

 <script>
  // bind change event to dropdown, when you change the dropdown
  // get the value of the selected option and put it in the input field
  document.getElementById('files').onchange = function(){     
     document.getElementById('file-info').value = document.getElementById('files').value;
 }
 </script>

jsfiddle: http://jsfiddle.net/N7ujB/

リピーターフィールドアドオンをお持ちの場合

「ファイル」などのフィールド名でリピーター フィールドを作成します。リピーター フィールド内に、「ファイル タイトル」と「ファイル アップロード」のフィールドを作成します。

次に、リピーター フィールドをループして、アップロードされたすべてのドキュメントを表示します。

<!-- create dropdown with list of file names and urls -->
<select id="files">
    <option value="">
        Select a file
    </option>
    <?php

    if ( get_field('files') ) {
        // loop through the uploaded files
        while(has_sub_field('files')) {

            // set variables for file title/uri
            $file = get_sub_field('file_upload');
            $file_uri = wp_get_attachment_url( $file );
            $file_title = ( get_sub_field('file_title') ) ? get_sub_field('file_title') : get_the_title( $file );

            // generate code for each option, including the file uri and title
            echo '<option value="' . $file_uri . '">' . $file_title . '</option>';
        }
    }

    ?>
</select>
于 2013-10-21T15:07:17.313 に答える
0
  1. 「ファイル名」=>「ファイル URL」の連想配列を使用します。
  2. for each ループを使用して、配列のすべての「ファイル名」要素を表示するドロップダウンを作成します。
  3. グローバル $customFields (バックエンドでは $custom.
  4. $customFields を使用して、フロント エンドに「ファイル URL」の値を表示します。
于 2013-10-21T15:26:29.943 に答える