子テーマで作業されていることを前提に書きます。
親テーマのcontent.phpを子テーマにコピーして、
そのcontent.phpに以下のコードがあります。
php
1<?php if ( is_search() ) : // Only display Excerpts for Search ?>
2 <div class="entry-summary">
3 <?php the_excerpt(); ?>
4 </div><!-- .entry-summary -->
5
それを、トップ画面でも抜粋表示されるようにコード || is_home() を付けたします。
php
1<?php if ( is_search() || is_home() ) : // Only display Excerpts for Search ?>
2 <div class="entry-summary">
3 <?php the_excerpt(); ?>
4 </div><!-- .entry-summary -->
5
これで抜粋表示されると思います。
デフォルトだと抜粋の表示は、
[...]
なのでそれを変更したい場合は、functions.phpに
php
1function new_excerpt_more($more) {
2 return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">続きを読む</a>';
3}
4add_filter('excerpt_more', 'new_excerpt_more');
5
これで、「続きを読む」と表示されます。
抜粋の文字数を変更したい場合は、
php
1function custom_excerpt_length( $length ) {
2 return 10;
3}
4add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
これで、10文字になります。
テンプレートタグ/the excerpt
参考まで。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/30 15:23