6.42 「最近のコメント」をフィードで配信する ★
P.583
コメントフィード用のテンプレート作成
・テンプレート名:コメント用フィード
・テンプレートの内容:次のサブテンプレート
・テンプレートの種類:カスタムインデックステンプレート
・出力ファイル名:comments.xml
<mt:HTTPContentType type="application/rss+xml" /><?xml version="1.0" encoding="<mt:publishCharset />"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title><mt:blogName remove_html="1" encode_xml="1" />へのコメント</title>
<link><mt:blogURL /></link>
<description><mt:blogName remove_html="1" encode_xml="1" />へのコメント</description>
<language><mt:blogLanguage ietf="1" /></language>
<pubDate><mt:comments lastn="1"><mt:commentDate format_name="rfc822" /></mt:comments></pubDate>
<generator>http://www.sixapart.com/movabletype/</generator>
<mt:comments lastn="15" sort_order="descend">
<item>
<title>「<mt:commentEntry><mt:entryTitle remove_html="1" encode_xml="1" />」へのコメント</mt:commentEntry></title>
<link><mt:commentEntry><mt:entryPermalink encode_xml="1" /></mt:commentEntry>#comment-<mt:commentID /></link>
<dc:creator><mt:commentAuthor /></dc:creator>
<pubDate><mt:commentDate format_name="rfc822" /></pubDate>
<guid><mt:commentEntry><mt:entryPermalink />#comment-<mt:commentID /></mt:commentEntry></guid>
<description><mt:commentBody remove_html="1" encode_xml="1" /></description>
<content:encoded><![CDATA[<mt:commentBody />]]></content:encoded>
</item>
</mt:comments>
</channel>
</rss>
P.584
<mt:comments lastn="20" sort_order="descend">
Auto-Discovery用のlink要素を出力する
「ヘッダー」テンプレートモジュール(サンプルテンプレート)
...前略...
<mt:if name="index_template">
<link rel="alternate" type="application/atom+xml" title="Atom" href="<mt:link template="feed_recent" />" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<mt:link template="rss" />" />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="<mt:link template="rsd" />" />
<link rel="alternate" type="application/rss+xml" title="RSS Comment" href="<mt:blogURL />comments.xml" />
<mt:unless name="main_index">
<link rel="start" href="<mt:blogURL />" title="Home" />
</mt:unless>
</mt:if>
...後略...
★「HTMLヘッダー」テンプレートモジュール(デフォルトテンプレート)
追加箇所は006です。
001:<meta http-equiv="Content-Type" content="text/html; charset=<$mt:PublishCharset$>" />
002:<meta name="generator" content="<$mt:ProductName version="1"$>" />
003:<link rel="stylesheet" href="<$mt:Link template="styles"$>" type="text/css" />
004:<link rel="start" href="<mt:BlogURL />" title="Home" />
005:<link rel="alternate" type="application/atom+xml" title="Recent Entries" href="<$mt:Link template="feed_recent"$>" />
006:<link rel="alternate" type="application/rss+xml" title="RSS Comment" href="<mt:BlogURL />comments.xml" />
007:<script type="text/javascript" src="<$mt:Link template="javascript"$>"></script>
008:<$mt:CCLicenseRDF$>
P.585
●サンプルテンプレートをカスタマイズする
「購読」ウィジェットテンプレート(サンプルテンプレート)
<dd class="syndicate">
<p><a href="<mt:link template="atom" />"><img src="<mt:staticWebPath />plugins/SampleTemplateSet/images/feed-icon-32x32.jpg" width="32" height="32" alt="Feed アイコン" title="このブログを購読" /></a><a href="<mt:link template="atom" />">このブログを購読</a></p>
<p><a href="<mt:blogURL />comments.xml" /><img src="<mt:staticWebPath />plugins/SampleTemplateSet/images/feed-icon-32x32.jpg" width="32" height="32" alt="Feed アイコン" title="コメントを購読" /></a><a href="<mt:blogURL />comments.xml" />コメントを購読</a></p>
</dd>
「スタイルシート」インデックステンプレート(サンプルテンプレート)
...前略...
.syndicate p {
margin-bottom: 3px;
}
...後略...
★「購読」ウィジェットテンプレート(デフォルトテンプレート)
追加箇所は5行目のみです。CSSの設定は不要です。
<div class="widget-syndication widget">
<div class="widget-content">
<ul>
<li><img src="<$mt:StaticWebPath$>images/status_icons/feed.gif" alt="購読する" width="9" height="9" /> <a href="<$mt:Link template="feed_recent"$>">このブログを購読</a></li>
<li><img src="<$mt:StaticWebPath$>images/status_icons/feed.gif" alt="購読する" width="9" height="9" /> <a href="<$mt:BlogURL$>comments.xml" />コメントを購読</a></li>
<mt:If name="search_results">
<mt:If tag="SearchString">
<li class="search-results-feed"><img src="<$mt:StaticWebPath$>images/status_icons/feed.gif" alt="購読する" width="9" height="9" /> <a href="<$mt:CGIPath$><$mt:SearchScript$>?<mt:IfTagSearch>tag<mt:else>search</mt:IfTagSearch>=<$mt:SearchString encode_url="1"$>&Template=feed&IncludeBlogs=<$mt:SearchIncludeBlogs$>&limit=<$mt:SearchMaxResults$>" title="<mt:IfTagSearch>「<$mt:SearchString$>」の検索結果を購読<mt:Else>タグ「<$mt:SearchString$>」を購読</mt:IfTagSearch>"><mt:IfTagSearch>タグ「<$mt:SearchString$>」のフィード<mt:Else>「<$mt:SearchString$>」を検索した結果のフィード</mt:IfTagSearch></a></li>
</mt:If>
</mt:If>
</ul>
</div>
</div>