[WordPress General] 投稿記事を指定した文字数で抜粋して…で省略する

memo.

[markdown]
`the_content()` のかわりに `the_excerpt()` を利用します。

> * [テンプレートタグ/the excerpt – WordPress Codex 日本語版](http://wpdocs.sourceforge.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/the_excerpt)

“`php:index.pho

“`

## カスタマイズ

いわゆるフィルターフックをすることで、文字数や省略文字などをカスタマイズできるそうです。

> * [WordPress:記事抜粋を表示するthe_excerptの使い方とカスタマイズのまとめ | PressStocker](http://pressstocker.com/the-excerpt/)

“`php:functions.php
//記事抜粋を表示する
function change_excerpt_mblength($length) {
return 40;
}
add_filter(‘excerpt_mblength’, ‘change_excerpt_mblength’);
function new_excerpt_more($more) {
return ‘ …’;
}
add_filter(‘excerpt_more’, ‘new_excerpt_more’);
“`

日本語版で運用する場合に必ず入れる [WP Multibyte Patch](http://eastcoder.com/code/wp-multibyte-patch/) の設定を利用できるとのこと。
[/markdown]