エントリー

freoのエントリーとページの編集画面でオプションの画像を表示する方法

【2018/03/16】ファイルの拡張子が .jpg.jpeg.png.gif の場合は、画像を表示し、それ以外の場合はファイル名を表示するように修正しました。

以前、freoのエントリーとページの編集画面で添付ファイルとイメージの画像を表示する方法 を紹介しましたが、今回はオプションで種類をファイルにし画像を登録した場合、編集画面で画像を表示する方法を紹介します。

エントリー編集の場合

templates/internals/admin/entry_form.html の56~64行目あたり(オプションの種類がファイルの部分)の

<!--{elseif $option.type == 'file'}-->
<dd>
  <input type="file" name="entry_associate[option][{$option.id}]" size="30" />
  <!--{if $input.entry_associate.option[$option.id]}-->
    <input type="checkbox" name="entry_associate[option_remove][{$option.id}]" id="label_option_{$option.id}" value="{$input.entry_associate.option[$option.id]}"{if $input.entry_associate.option_remove[$option.id]} checked="checked"{/if} /> <label for="label_option_{$option.id}">{$input.entry_associate.option[$option.id]}を削除</label>
    <input type="hidden" name="entry_associate[option][{$option.id}]" value="{$input.entry_associate.option[$option.id]}" />
  <!--{/if}-->
</dd>
<!--{/if}-->

の部分を、

<!--{elseif $option.type == 'file'}-->
<dd>
  <input type="file" name="entry_associate[option][{$option.id}]" size="30" />
  <!--{if $input.entry_associate.option[$option.id]}-->
    <br />現在の{$option.name}<br />
    <a href="{$freo.core.http_url}{$smarty.const.FREO_FILE_DIR}entry_options/{$freo.query.id}/{$option.id}/{$input.entry_associate.option[$option.id]}"><!--{if $input.entry_associate.option[$option.id]|regex_match:'/\.(jpe?g|png|gif)$/i'}--><img src="{$freo.core.http_url}{$smarty.const.FREO_FILE_DIR}entry_options/{$freo.query.id}/{$option.id}/{$input.entry_associate.option[$option.id]}" alt="現在の{$option.name}" width="100" /><!--{else}-->{$input.entry_associate.option[$option.id]}<!--{/if}--></a>
    <input type="checkbox" name="entry_associate[option_remove][{$option.id}]" id="label_option_{$option.id}" value="{$input.entry_associate.option[$option.id]}"{if $input.entry_associate.option_remove[$option.id]} checked="checked"{/if} /> <label for="label_option_{$option.id}">{$input.entry_associate.option[$option.id]}を削除</label>
    <input type="hidden" name="entry_associate[option][{$option.id}]" value="{$input.entry_associate.option[$option.id]}" />
  <!--{/if}-->
</dd>
<!--{/if}-->

に変更(赤字を追加)します。
【2018/03/16】ファイルの拡張子が .jpg.jpeg.png.gif の場合は、画像を表示し、それ以外の場合はファイル名を表示するように修正(ピンク字の部分を追加)。

ページ編集の場合

templates/internals/admin/page_form.html の58~66行目あたり(オプションの種類がファイルの部分)の

<!--{elseif $option.type == 'file'}-->
<dd>
  <input type="file" name="page_associate[option][{$option.id}]" size="30" />
  <!--{if $input.page_associate.option[$option.id]}-->
    <input type="checkbox" name="page_associate[option_remove][{$option.id}]" id="label_option_{$option.id}" value="{$input.page_associate.option[$option.id]}"{if $input.page_associate.option_remove[$option.id]} checked="checked"{/if} /> <label for="label_option_{$option.id}">{$input.page_associate.option[$option.id]}を削除</label>
    <input type="hidden" name="page_associate[option][{$option.id}]" value="{$input.page_associate.option[$option.id]}" />
  <!--{/if}-->
</dd>
<!--{/if}-->

の部分を、

<!--{elseif $option.type == 'file'}-->
<dd>
  <input type="file" name="page_associate[option][{$option.id}]" size="30" />
  <!--{if $input.page_associate.option[$option.id]}-->
    <br />現在の{$option.name}<br />
    <a href="{$freo.core.http_url}{$smarty.const.FREO_FILE_DIR}page_options/{$freo.query.id}/{$option.id}/{$input.page_associate.option[$option.id]}"><!--{if $input.page_associate.option[$option.id]|regex_match:'/\.(jpe?g|png|gif)$/i'}--><img src="{$freo.core.http_url}{$smarty.const.FREO_FILE_DIR}page_options/{$freo.query.id}/{$option.id}/{$input.page_associate.option[$option.id]}" alt="現在の{$option.name}" width="100" /><!--{else}-->{$input.page_associate.option[$option.id]}<!--{/if}--></a>
    <input type="checkbox" name="page_associate[option_remove][{$option.id}]" id="label_option_{$option.id}" value="{$input.page_associate.option[$option.id]}"{if $input.page_associate.option_remove[$option.id]} checked="checked"{/if} /> <label for="label_option_{$option.id}">{$input.page_associate.option[$option.id]}を削除</label>
    <input type="hidden" name="page_associate[option][{$option.id}]" value="{$input.page_associate.option[$option.id]}" />
  <!--{/if}-->
</dd>
<!--{/if}-->

に変更(赤字を追加)します。
【2018/03/16】ファイルの拡張子が .jpg.jpeg.png.gif の場合は、画像を表示し、それ以外の場合はファイル名を表示するように修正(ピンク字の部分を追加)。

すると編集画面の
ファイル 63-1.jpg
だった部分が
ファイル 63-2.jpg
になります。

※添付ファイルが画像以外の場合は下のようにリンク表示になります。
ファイル 63-3.jpg

ページ移動

関連エントリー

コメント

  • コメントはまだありません。

コメント登録

  • コメントを入力してください。
  • 一旦登録したコメントは、あとで編集できませんのでご注意下さい。
登録フォーム

基本的には「全体に公開」されますが、内容によっては管理人の方で公開を制限する場合がありますので、その旨ご了承下さい。

ユーティリティ

2024年03月

- - - - - 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31 - - - - - -

キーワード検索

キーワード検索フォーム

ユーザー

  • cccのアバター

新着画像

ブログパーツ

Twitter

Twilogを見る

Feed