TwentyTwelve 抜粋記事表示時の’続きを読む’の設定

ワードプレステーマTwentyTwelveは、残念ながらデフォルトでは抜粋記事表示にしても’続きを読む’のリンクが表示されません…。’[…]’だけですよね?

TwentyTen、Elevenではデフォルトで’続きを読む⇒’のリンクが表示されていたのですが、Twelveではその機能は継承されなかったらしいです…(フォーラム参照

正直、これには大変参りました…(汗 最初は、無理だと思いあきらめていましたし…(苦笑

しかし、不思議なモノで、アッと思った時に情報が入ってくるモンなんですね。そのものズバリの答えは得ることが出来なかったのですが、ヒントを得て試してみたところ…、出来ちゃいましたww

って事で、抜粋記事表示をした時に’続きを読む⇒’のリンクが表示される様にしていきましょう♫ ただし、1点だけ注意して下さい。今回はスタイルシートではなく’functions.php’を直接カスタマイズしていきます。

つまり、小テーマ作成の有無に関わらずTwentyTwelve親テーマのファイルをイジりますので、バージョンアップの際は全てのデータが消去されてしまいます。(デフォルトに戻る)

ファイルのバックアップ/ファイルコピーの保存/当ページのブックマーク/などをしてから、バージョンアップする様にして下さい。

それでは、管理画面より「外観」⇒「テーマ編集」から’TwentyTwelve’の’functions.php’を開いて下さい。そして、別のタブで’TwentyEleven’の’functions.php’を開いて下さい。(小テーマを使用している方は、小テーマ側のテンプレートファイルを編集して下さい)

えぇ、そうなんです。Elevenから継承されなかったので、自力で継承させます(笑 つまり、パクる拝借する訳です。両方のファイルを開いたら、まずは’Elevenのfunctions.php’中から以下の部分を探して下さい。

/**
 * Sets the post excerpt length to 40 words.
 *
 * To override this length in a child theme, remove the filter and add your own
 * function tied to the excerpt_length filter hook.
 */
function twentyeleven_excerpt_length( $length ) {
	return 40;
}
add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );

if ( ! function_exists( 'twentyeleven_continue_reading_link' ) ) :
/**
 * Returns a "Continue Reading" link for excerpts
 */
function twentyeleven_continue_reading_link() {
	return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) . '</a>';
}
endif; // twentyeleven_continue_reading_link

/**
 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyeleven_continue_reading_link().
 *
 * To override this in a child theme, remove the filter and add your own
 * function tied to the excerpt_more filter hook.
 */
function twentyeleven_auto_excerpt_more( $more ) {
	return ' …' . twentyeleven_continue_reading_link();
}
add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );

/**
 * Adds a pretty "Continue Reading" link to custom post excerpts.
 *
 * To override this link in a child theme, remove the filter and add your own
 * function tied to the get_the_excerpt filter hook.
 */
function twentyeleven_custom_excerpt_more( $output ) {
	if ( has_excerpt() && ! is_attachment() ) {
		$output .= twentyeleven_continue_reading_link();
	}
	return $output;
}
add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );

で、コレを’Elevev’のところを’Twelve’に変更して’Twelveのfunctions.php’にそのままコピー&ペーストします。こんな感じにです。

add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );

/**
 * Sets the post excerpt length to 40 words.
 * ’続きを読む’TwentyElevenから拝借
 * To override this length in a child theme, remove the filter and add your own
 * function tied to the excerpt_length filter hook.
 */
function twentytwelve_excerpt_length( $length ) {
	return 40;
}
add_filter( 'excerpt_length', 'twentytwelve_excerpt_length' );

if ( ! function_exists( 'twentytwelve_continue_reading_link' ) ) :
/**
 * Returns a "Continue Reading" link for excerpts
 */
function twentytwelve_continue_reading_link() {
	return ' <a href="'. esc_url( get_permalink() ) . '">' . __( '続きを読む <span class="meta-nav">→</span>', 'twentytwelve' ) . '</a>';
}
endif; // twentytwelve_continue_reading_link

/**
 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentytwelve_continue_reading_link().
 *
 * To override this in a child theme, remove the filter and add your own
 * function tied to the excerpt_more filter hook.
 */
function twentytwelve_auto_excerpt_more( $more ) {
	return ' …' . twentytwelve_continue_reading_link();
}
add_filter( 'excerpt_more', 'twentytwelve_auto_excerpt_more' );

/**
 * Adds a pretty "Continue Reading" link to custom post excerpts.
 *
 * To override this link in a child theme, remove the filter and add your own
 * function tied to the get_the_excerpt filter hook.
 */
function twentytwelve_custom_excerpt_more( $output ) {
	if ( has_excerpt() && ! is_attachment() ) {
		$output .= twentytwelve_continue_reading_link();
	}
	return $output;
}
add_filter( 'get_the_excerpt', 'twentytwelve_custom_excerpt_more' );

/**
 * Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link.
 *
 * @since Twenty Twelve 1.0
 */

緑の部分がTwenty Elevenからコピーしてきたところです。コピペしたら、’ファイルの更新’を忘れずにして下さい。

また、’続きを読む’の文字は、お好きな任意の言葉に変える事が出来ます。例えば、’全文表示’とか’全部読む’などですね。

この’functions.php’のファイル更新が完了したら、各テンプレートファイルで抜粋表示にすると、自動的に’続きを読む’のリンクが表示される様になります。

大変お疲れ様でした!!コレで無事任務完了です(笑

WordPressデザインブック ステップバイステップ形式でマスターできる
WordPressデザインブック ステップバイステップ形式でマスターできる

 


にほんブログ村 ブログブログ ブログノウハウへ

2 thoughts on “TwentyTwelve 抜粋記事表示時の’続きを読む’の設定

  1. ピンバック: TwentyTwelve 記事の全文表示/抜粋表示の表示変更 | 初めてのワードプレス カスタマイズ

  2. ピンバック: バージョンアップ時に気をつけたい事 | 初めてのワードプレス カスタマイズ

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です