Wordpress > フィードテンプレートのカスタマイズ

テンプレートファイルを変更

feedテンプレートはwp-includes内にあるfeed-atom.php、feed-atom-comments.php、feed-rdf.php、feed-rss2.php、feed-rss2-comments.phpとか。include内のファイルをいじるのは嫌だ。もしWordpressをバージョンアップしたら、上書きされてまうし。

そこで、テーマフォルダに feed-rss2.php を新たに作る。

そして、functions.phpに以下
  1. // rss2 のテンプレートを変更
  2. remove_filter('do_feed_rss2', 'do_feed_rss2', 10);
  3. function custom_feed_rss2() {
  4. load_template( get_template_directory() . '/feed-rss2.php' );
  5. }
  6. add_action('do_feed_rss2', 'custom_feed_rss2', 10, 1);
  7.  
ちなみに、デフォルトの feed は rss2 、らしい。


全文表示にする

wp-includes内のfeed-rss2.phpは、管理画面の「表示設定>RSS/Atom フィードでの各投稿の表示」で「全文を表示」を選んでいても、抜粋しか表示されないという、怪奇現象。

wp-includes/feed-rss2.php
  1. <?php if (get_option('rss_use_excerpt')) : ?>
  2. <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
  3. <?php else : ?>
  4. <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
  5. <?php if ( strlen( $post->post_content ) > 0 ) : ?>
  6. <content:encoded><![CDATA[<?php the_content_feed('rss2') ?>]]></content:encoded>
  7. <?php else : ?>
  8. <content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
  9. <?php endif; ?>
  10. <?php endif; ?>
  11.  
これを以下に変更

my-theme/feed-rss2.php
  1. <?php if (get_option('rss_use_excerpt')) : ?>
  2. <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
  3. <?php else : ?>
  4. <description><![CDATA[<?php the_content_feed('rss2') ?>]]></description>
  5. <content:encoded><![CDATA[<?php the_content_feed('rss2') ?>]]></content:encoded>
  6. <?php endif; ?>
  7.  







最終更新:2012年10月30日 20:35