entryでは本文抜粋だけ表示

記事一覧(「URL/entry」)では本文抜粋のみ表示、というのを「続きを読む」機能やネタバレボタン機能を使わずに実現するカスタマイズです。解りにくい説明ですが、まぁ当サイトの/entryのような表示方法です。

下準備

オプション管理で本文概要用のオプションを作ります。以下はその例です。

  • オプション名:summary
  • オプション名:本文の要約
  • 利用対象:すべて
  • 種類:複数行入力
  • 必須:任意

編集するテンプレート

  • templates/internals/default/default.html

トップページのみ表示を変更する」カスタマイズをしている場合は

  • templates/internals/entry/default.html

ここの、本文を表示するループ中の

<!--{if $entry_texts[$entry.id].excerpt}-->
	{$entry_texts[$entry.id].excerpt|smarty:nodefaults}
<!--{/if}-->
<!--{if $entry_texts[$entry.id].more}-->
	<p><a href="{$freo.core.http_file}/view/{if $entry.code}{$entry.code}{else}{$entry.id}{/if}?continue=1#continue" title="No.{$entry.id}の続き">続きを読む</a></p>
<!--{/if}-->

を、以下のように変更します。

<!--{if $entry_associates[$entry.id].option}-->
	<p>{$entry_associates[$entry.id].option.summary}</p>
	<p class="continue"><a href="{$freo.core.http_file}/view/{if $entry.code}{$entry.code}{else}{$entry.id}{/if}" title="「{$entry.title}」全文表示">Read More</a></p>
<!--{elseif $entry_texts[$entry.id].excerpt|smarty:nodefaults|strip_tags|count_characters < 100}-->
	{$entry_texts[$entry.id].excerpt|smarty:nodefaults}
<!--{elseif $entry_texts[$entry.id].excerpt}-->
	<p>{$entry_texts[$entry.id].excerpt|smarty:nodefaults|strip_tags|mb_truncate:100:'...'|escape}</p>
	<p class="continue"><a href="{$freo.core.http_file}/view/{if $entry.code}{$entry.code}{else}{$entry.id}{/if}" title="「{$entry.title}」全文表示">Read More</a></p>
<!--{/if}-->

こうすると、記事一覧(「URL/entry」)で

  • オプション「本文の要約」が入力されている場合はそれを表示
  • オプション「本文の要約」が入力されていない場合は本文の冒頭100文字(全角は2文字換算?)をプレーンテキストで表示

し、どちらの場合も「Read More」に記事単体(「view/ID」)へのリンクが貼られます。また、本文要約が入力されておらず本文が「100文字(全角は2文字換算?)未満」の場合は本文がそのまま表示されます。