サポート » 使い方全般 » カテゴリーアーカイブの「続きを読む」を「『タイトル』の続きを読む」

  • 解決済 pyonko

    (@pyonko)


    いつもお世話になっております。
    twentytenの子テーマで運用中ですが、カテゴリーアーカイブで表示される「抜粋」の末尾につけられる「続きを読む →」を「○○の続きを読む →」に変更しようとして、
    twentytenのloop.phpの

    <?php /* How to display all other posts. */ ?>
    ・・・(中略)・・・
    <div class="entry-content">
    				<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
    				<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    			</div><!-- .entry-content -->

    の、
    the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) );
    を、
    <?php echo '<a href="'. get_permalink() . '">「' . get_the_title(). '」の続きを読む <span>&rarr;</span></a>'; ?>
    としてみましたが、変化がありません。

    また、一部の情報には、functions.phpで、親ページの、
    function twentyten_continue_reading_link()
    を子テーマで上書きする方法で、

    function twentyten_continue_reading_link() {
     return '<a href="'. get_permalink() . '">「' . get_the_title(). '」の続きを読む <span>&rarr;</span></a>';
    }

    などとして子テーマのfunctions.phpに追加したところ、全てがエラー表示になってビックリしてしまいました。

    解決方法があればどうかご教示ください。よろしくお願いします。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック投稿者 pyonko

    (@pyonko)

    http://ja.forums.wordpress.org/topic/8715
    の記事を参考とし、親テーマ(tewntytenのfunctions.php)のコメントも踏まえながら、下記の通り進めてみました。

    function alterd_continue_reading_link() {
     return '<a href="'. get_permalink() . '">「' . get_the_title(). '」の続きを読む <span>&rarr;</span></a>';
    }
    add_filter('excerpt_more', 'alterd_continue_reading_link');
    
    function remove_twentyten_continue_reading_link() {
    	remove_filter('excerpt_more', 'twentyten_continue_reading_link');
    }
    add_filter('after_setup_theme', 'remove_twentyten_continue_reading_link');

    しかし、カテゴリーアーカイブは「続きを読む →」のまま変化がありません。
    前回書き忘れてしまったのですが、当方は本文と抜粋の両方に記述し、カテゴリーアーカイブに”抜粋+「続きを読む →」”となるようにしています。

    以上のプロセスですが、間違いをご指摘いただければ幸いです。どうかよろしくお願い致します。

    トピック投稿者 pyonko

    (@pyonko)

    落ち着いてよく見直したところ、フックさせるところが違っていました。以下で解決しました。

    // カテゴリーアーカイブの「続きを読む」を「titleの続きを読む」に変更する
    function altered_continue_reading_link() {
         return '<a href="'. get_permalink() . '">「' . get_the_title(). '」の続きを読む <span>&rarr;</span></a>';
    }
    function altered_custom_excerpt_more( $output ) {
        if ( has_excerpt() && ! is_attachment() ) {
    	$output .= altered_continue_reading_link();
        }
        return $output;
    }
    add_filter('get_the_excerpt', 'altered_custom_excerpt_more');
    
    function remove_twentyten_custom_excerpt_more() {
    	remove_filter('get_the_excerpt', 'twentyten_custom_excerpt_more');
    }
    add_filter('after_setup_theme', 'remove_twentyten_custom_excerpt_more');

    私自身の備忘録となりました。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「カテゴリーアーカイブの「続きを読む」を「『タイトル』の続きを読む」」には新たに返信することはできません。