1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

<mt:EntryBody>で<mt:EntryExcerpt>のように○文字より多くなったら、末尾に「…」をつける

Posted at

本文の文字数をカウントして比較

MTML
<$mt:EntryBody count_characters="1" setVar="cntWord"$>

<p><$mt:EntryBody words="150" convert_breaks="0" remove_html="1"$><mt:If name="cntWord" gt="150">…</mt:If></p>

本文の文字数をcntWordに格納。
本文出力の末尾にmt:ifをつかって、cntWordの文字数を比較。
gtモディファイアは「~より大きい場合」となります。

本文以外は「words」が使えなかったので「trim_to」で代用

MTML
<mt:If tag="EntryTitle">
<$mt:EntryTitle count_characters="1" setVar="cntWord"$>
<$mt:EntryTitle escape="html" trim_to="85"$><mt:If name="cntWord" gt="85">…</mt:If>
</mt:If>
1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?