WordPress Hack : フィードの中に関連記事を追加する
フィードにも関連記事が表示されれば面白いかなと思いついたので、表示してみました。
過去の記事もフィードから確認できるので、良い情報にも巡り合うかもしれません。
フィードの中に関連記事を追加する方法
今回は、wp-rss2.php を改造しました。
もちろんのことですが、このHackにはWordPress Related Entries 2.0のプラグインが必要です。
修正箇所は、
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<?php if (get_settings('rss_use_excerpt')) : ?>
<description><![CDATA[<?php the_excerpt_rss() ?><br /><b>Related Posts:</b><?php related_posts(); ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_excerpt_rss() ?><br /><b>Related Posts:</b><?php related_posts(); ?>]]></description>
<?php if ( strlen( $post->post_content ) > 0 ) : ?>
<content:encoded><![CDATA[<?php the_content('', 0, '') ?><br /><b>Related Posts:</b><?php related_posts(); ?>]]></content:encoded>
<?php else : ?>
<content:encoded><![CDATA[<?php the_excerpt_rss() ?><br /><b>Related Posts:</b><?php related_posts(); ?>]]></content:encoded>
<?php endif; ?>
非常に解りにくいですね・・・
wp-rss2.php の41行目、43行目、45行目、47行目に
<b>Related Posts:</b><?php related_posts(); ?>
このコードを挿入しただけです。
するとRSSリーダーで取得したときに関連記事も表示される。
僕が使ってるファイルをUPしときます。
wp-rss2.txt
wp-rss2.phpにリネイムし、wp-config.php と同じ箇所にアップロードします。上書きになると思いますが。
Related posts
Tags: WordPress
