【freo】【freoTips】【プラグイン系TIPS】同人イベントプラグインで未来のイベントのみ表示する方法
- 2012/10/30 23:42
- 同人イベントプラグイン
- 68
当サイトで配布しているイベント登録プラグインを利用すると、イベント参加予定を表示することができます。
デフォルトだと全件表示されてしまうため、これを未来のイベントのみに絞りたい場合は、テンプレートを編集する必要があります。
たとえば、[templates/plugins/event/default.html]の38行目~52行目を、以下のように変更します。
<!--{foreach from=$plugin_events|smarty:nodefaults item='plugin_event'}--> <!--{if $plugin_event.datetime|date_format:'%Y/%m/%d' >= $smarty.now|date_format:'%Y/%m/%d'}--> <tr> <td><a href="{$freo.core.http_file}/event/view/{$plugin_event.id}">{$plugin_event.datetime|date_format:'%Y/%m/%d'}<!--{if $plugin_event_files[$plugin_event.id].file}--><br /><img src="{$freo.core.http_url}{$smarty.const.FREO_FILE_DIR}plugins/event_files/{$plugin_event.id}/{$plugin_event_files[$plugin_event.id].file}" alt="{$plugin_event.title}" /><!--{/if}--></a></td> <td> <!--{if $plugin_event.url}--><a href="{$plugin_event.url}" target="_blank">{$plugin_event.title}</a> <!--{else}-->{$plugin_event.title} <!--{/if}--> </td> <td> <!--{if $plugin_event.space}--><!--{if $plugin_event.hall}-->{$plugin_event.hall} <!--{/if}-->{$plugin_event.space}<!--{/if}--><br /><!--{if $plugin_event.style}-->({$plugin_event.style}<!--{if $plugin_event.itakucircle}-->|<!--{if $plugin_event.itakuurl}--><a href="{$plugin_event.itakuurl}" target="_blank">{$plugin_event.itakucircle}様</a><!--{else}-->{$plugin_event.itakucircle}様<!--{/if}--><!--{/if}-->)<!--{/if}--> </td> <td>{$plugin_event.name}</td> <td> <!--{if $plugin_event.category_id}-->【カテゴリー:<a href="{$freo.core.http_file}/event?category_id={$plugin_event.category_id}">{$plugin_event_categories[$plugin_event.category_id].name}</a>】<br /><!--{/if}--> <!--{if $plugin_event_tags[$plugin_event.id]|smarty:nodefaults}-->【タグ:<!--{foreach from=$plugin_event_tags[$plugin_event.id]|smarty:nodefaults item='plugin_event_tag' name='loop'}--><a href="{$freo.core.http_file}/event?tag={$plugin_event_tag|smarty:nodefaults|escape:'url'}">{$plugin_event_tag}</a><!--{if !$smarty.foreach.loop.last}-->, <!--{/if}--><!--{/foreach}-->】<br /><!--{/if}--> <!--{if $plugin_event.coupling}-->カップリング:{$plugin_event.coupling}<br /><!--{/if}--> <!--{if $plugin_event.text}-->{$plugin_event.text|smarty:nodefaults|strip_tags|mb_truncate:20:'...'|escape}<!--{/if}--> </td> </tr> <!--{/if}--> <!--{/foreach}-->
こうすると、今の時点よりも未来の開催日時のイベントのみが表示されます。<!--{foreach from=$plugin_events|smarty:nodefaults item='plugin_event'}-->~</foreach>
で繰り返しているイベントの内容を表示している部分に、<!--{if $plugin_event.datetime|date_format:'%Y/%m/%d' >= $smarty.now|date_format:'%Y/%m/%d'}-->~<!--{/if}--->
という制限を加えて、未来の日付だけを表示するようにしています。
<!--{if $plugin_event.datetime|date_format:'%Y/%m/%d' >= $smarty.now|date_format:'%Y/%m/%d'}-->~<!--{/if}--->
は、[templates/plugins/event/default.html]以外でも利用できます。
イベント登録プラグインで紹介しているデフォルト画面・ページ画面でイベントを表示する方法を利用して、ページ上でイベントを表示する時だけは上記のように未来のイベントだけを表示し、過去イベント参加履歴としてイベント登録プラグインのデフォルト画面(freo/index.php/event)を表示し、そこでは全件表示するというようなことも可能です。