取得URL
http://example.com/?feed=rss2
http://example.com/feed/
http://example.com/feed/rss/
カテゴリー指定も可能。
http://domain.tld/category/categoryname/feed/ (Permalink format)
http://domain.tld/wp-rss2.php?cat=33 (Default format)
RSSのURLでパースエラーが出た場合
サーバーによってはこのようなエラーが出る場合があるようだ。
This page contains the following errors:
error on line 2 at column 6: XML declaration allowed only at the start of the document
….
原因は未検証だが、下の方法で解決出来た。
こちらを参考に、
以下のファイルの先頭に、
wp-includes/feed-rss2.php
wp-includes/feed-rss2-comments.php
ob_end_clean();
を追加する。
RSS feed へのサムネイル追加方法
まずはじめに見つけたのがこちら。
if(!function_exists('rss_post_thumbnail')):
function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '
' . get_the_post_thumbnail($post->ID, array(120,120)) . '
' . $content; } return $content; } add_filter('the_excerpt_rss', 'rss_post_thumbnail'); add_filter('the_content_feed', 'rss_post_thumbnail'); endif;
これはfeed中のcontentの要素に、サムネイルをくっつけて吐き出させるもの。
これでも良いが、新規にサムネイル用の要素を作る方法もある→url。
// add post-thumbnail element
if(!function_exists('rss_post_thumbnail_as_elem')):
function rss_post_thumbnail_as_elem(){
global $post;
$output = '';
$thumbnail_ID = get_post_thumbnail_id( $post->ID );
if($thumbnail_ID){
$thumbnail = wp_get_attachment_image_src($thumbnail_ID, array(120,120));
$output .= '';
$output .= ''. $thumbnail[0] .' ';
$output .= ''. $thumbnail[1] .' ';
$output .= ''. $thumbnail[2] .' ';
$output .= ' ';
}
echo $output;
}
add_action('rss2_item', 'rss_post_thumbnail_as_elem');
endif;
rss2_item というアクションフックを使えば、色々変えられる様子。
jsonで取得したい場合
また、こちらのプラグインを使用するとxmlでなくjsonで受け取る事も可能。
クロスドメインでフィードを取得したいときなど、便利そうですね。
参考にさせて頂いた著者の方々、ありがとうございました!