抜粋に表示する「続きを読む」の表示を変えたいときのメモです
twentytenでは、<?php the_excerpt(); ?>記述で、抜粋文40文字、最後に「続きを読む→」と表示されるように、functions.phpに記述があります。
//抜粋の文字数(プラグイン「wp-multibyte-patch」を導入している場合はそちらが優先) function twentyten_excerpt_length( $length ) { return 40; } add_filter( 'excerpt_length', 'twentyten_excerpt_length' ); //続きを読む→ function twentyten_continue_reading_link() { return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) . '</a>'; } //自動的に「続きを読む→」を表示する function twentyten_auto_excerpt_more( $more ) { return ' …' . twentyten_continue_reading_link(); } add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
上記のコードで、class=”meta-nav” のCSS指定を変えてやればコントロールできると思いますが、
twentyten以外では、functions.phpにコードを追加して変更することに。
テンプレートに記述
「抜粋文」と「続きを読む」を別々に表示するために分けて書くことに…
wordpressのシステムが、class=”morelink” を指定してやると単一ページにリンクを貼ってくれます
<?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="morelink"><span class="morelink">続きを読む</span></a>
functions.phpに下記のコードを記述して、抜粋文に付加している「続きを読む」を削除して「…」だけにする
wordpressのデフォルトでは「…」だけを表示するようなので、この指定はいらないと思いますが、
twentytenを利用している場合は、追加することで設定を上書きします。
function new_excerpt_more($post) { return ' ...'; } add_filter('excerpt_more', 'new_excerpt_more');
functions.phpに下記のコードを記述して抜粋文の文字数をコントロール
(プラグイン「wp-multibyte-patch」を導入している場合はそちらが優先)
function new_excerpt_mblength($length) { return 80; } add_filter('excerpt_mblength', 'new_excerpt_mblength');
CSSで、class=”morelink” に「続きを読む」の見た目を指定
指定例
color:#ff0000; text-decoration: none; float:right;