FacebookのノートへブログのRSSを読み込ませることができるということなので、やってみました。WordPressでは通常のAtomフィード以外にもフィードを作成できますから、ちょっと頑張って作ってみました。
コンテンツ自体はブログの方にあるので、Facebookへは、タイトルと誘導リンクだけが表示されるようにしてあります。read more… とURLが重なっているのですが、メッセージ一覧に表示されるときにURLが一緒に表示された方がいいかと考えて、そのようにしました。
require('/var/www/wordpress/wp-load.php');
header('Content-Type: ' . feed_content_type('atom') . '; charset=' . get_option('blog_charset'), true);
$more = 1;
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
<feed
xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0"
xml:lang="<?php echo get_option('rss_language'); ?>"
xml:base="<?php bloginfo_rss('url') ?>/wp-atom.php"
<?php do_action('atom_ns'); ?>
>
<title type="text"><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
<subtitle type="text"><?php bloginfo_rss("description") ?></subtitle>
<updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></updated>
<link rel="alternate" type="text/html" href="<?php bloginfo_rss('url') ?>" />
<id><?php bloginfo('atom_url'); ?></id>
<link rel="self" type="application/atom+xml" href="<?php self_link(); ?>" />
<?php do_action('atom_head'); ?>
<?php
$atom_posts = get_posts("posts_per_page=20");
if ($atom_posts) {
foreach ($atom_posts as $post_t) :
setup_postdata($post_t);
$cat=get_the_category(); if (strcmp($cat[0]->cat_name, 'Twitter')==0) continue;
?>
<entry>
<author><name>hiro345</name></author>
<title><![CDATA[<?php echo $post_t->post_title; ?>]]></title>
<link rel="alternate" type="text/html" href="<?php echo get_permalink($post_t->ID); ?>" />
<id><?php echo $post_t->ID; ?></id>
<updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', $post_t->post_modified_gmt, true);</updated>
<published><?php echo mysql2date('Y-m-d\TH:i:s\Z', $post_t->post_date_gmt, true); ?></published>
<?php the_category_rss('atom') ?>
<summary type="<?php html_type_rss(); ?>"><![CDATA[<?php echo $post_t->post_title; ?>, Please click <a href="<?php echo get_permalink($post_t->ID); ?>"> read more </a> … <?php echo get_permalink($post_t->ID); ?>]]></summary>
<?php do_action('atom_entry'); ?>
</entry>
<?php
endforeach;
}
?>
</feed>
*post_modified, post_date はGMTではなかったので、post_modified_gmt, post_date_gmt を使うように修正しました。(2011/06/17)
これを用意してから、Facebookで、ノートを読むページを開きます。そこで表示される「インポート設定を編集」のリンクをクリックして、Facebook専用のAtomフィードを指定しました。ちなみに、ひとつもノートがないと表示できないので、その場合は1つノートを書きます。