抜粋表示させる文字数を変更したい
[php]<?php the_content(); ?>[/php]
【を変更、】
[php]<?php the_excerpt(); ?>[/php]
【function.phpに記述します】
[php]function my_excerpt_length($length) {
return 80;
}
add_filter(‘excerpt_length’, ‘my_excerpt_length’);[/php]
【[…]を削除】
[php]function my_excerpt_more($more) {
return ”;
}
add_filter(‘excerpt_more’, ‘my_excerpt_more’);[/php]
【別の文字に変更】
[php]function my_excerpt_more($more) {
return ‘…’;
}
add_filter(‘excerpt_more’, ‘my_excerpt_more’);[/php]
【変更後、その記事へのリンクを追加する】
[php]function my_excerpt_more($post) {
return ‘<a href="’. get_permalink($post->ID) . ‘">’ . ‘…続きを読む’ . ‘</a>’;
}
add_filter(‘excerpt_more’, ‘my_excerpt_more’);[/php]
【ページのごとに文字数を変更。category.phpに30文字】
[php]<?php echo mb_substr(get_the_excerpt(), 0, 30); ?>[/php]
※mb_substr(対象の文字列, 取り出し開始位置, 取り出す文字数)