6.41 カテゴリ別にフィードを配信する ★
P.580
カテゴリ別にフィード用のテンプレート作成
テンプレート名:カテゴリ別フィード
テンプレートの内容:次の内容を設定
<mt:HTTPContentType type="application/atom+xml" /><?xml version="1.0" encoding="<mt:publishCharset />"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><mt:categoryLabel /> - <mt:blogName remove_html="1" encode_xml="1" /></title>
<link rel="alternate" type="text/html" href="<mt:blogURL encode_xml="1" />" />
<link rel="self" type="application/atom+xml" href="<mt:link template="atom" />" />
<id>tag:<mt:blogHost exclude_port="1" encode_xml="1" />,<mt:templateCreatedOn format="%Y-%m-%d" />:<mt:blogRelativeURL encode_xml="1" />/<mt:blogID /><mt:categoryID /></id>
<updated><mt:entries lastn="1"><mt:entryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ" /></mt:entries></updated>
<mt:if tag="blogDescription"><subtitle><mt:blogDescription remove_html="1" encode_xml="1" /></subtitle></mt:if>
<generator uri="http://www.sixapart.com/movabletype/"><mt:productName version="1" /></generator>
<mt:entries lastn="15">
<entry>
<title><mt:entryTitle remove_html="1" encode_xml="1" /></title>
<link rel="alternate" type="text/html" href="<mt:entryPermalink encode_xml="1" />" />
<id>tag:<mt:blogHost exclude_port="1" encode_xml="1" />,<mt:templateCreatedOn format="%Y-%m-%d" />:<mt:blogRelativeURL encode_xml="1" />/<mt:blogID /><mt:categoryID /><mt:entryID /></id>
<published><mt:entryDate utc="1" format="%Y-%m-%dT%H:%M:%SZ" /></published>
<updated><mt:entryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ" /></updated>
<summary><mt:entryExcerpt remove_html="1" encode_xml="1" /></summary>
<author>
<name><mt:entryAuthorDisplayName encode_xml="1" /></name>
<mt:if tag="entryAuthorURL"><uri><mt:entryAuthorURL encode_xml="1" /></uri></mt:if>
</author>
<mt:entryCategories>
<category term="<mt:categoryLabel encode_xml="1" />" scheme="http://www.sixapart.com/ns/types#category" />
</mt:entryCategories>
<mt:entryIfTagged><mt:entryTags><category term="<mt:tagName normalize="1" encode_xml="1" />" label="<mt:tagName encode_xml="1" />" scheme="http://www.sixapart.com/ns/types#tag" />
</mt:entryTags></mt:entryIfTagged>
<content type="html" xml:lang="<mt:blogLanguage ietf="1" />" xml:base="<mt:blogURL encode_xml="1" />">
<mt:entryBody encode_xml="1" />
<mt:entryMore encode_xml="1" />
</content>
</entry>
</mt:entries>
</feed>
P.581
...前略...
<link rel="self" type="application/atom+xml" href="<mt:link template="feed_recent" />" />
...後略...
%-c/atom.xml
Auto-Discovery用のlink要素を出力する
「ヘッダー」テンプレートモジュール(サンプルテンプレート)
...前略...
<mt:if name="archive_class" eq="category-archive">
<link rel="alternate" type="application/atom+xml" title="Category Atom" href="<mt:blogArchiveURL /><mt:subCategoryPath />/atom.xml" />
</mt:if>
...後略...
★「カテゴリ別ブログ記事リスト」アーカイブテンプレート(デフォルトテンプレート)
追加箇所は005~007です。このテンプレートはカテゴリアーカイブ専用ですが、日付ベースのカテゴリアーカイブで出力しないよう、ifタグで007のlink要素をコンテナしています。
...前略...
001:<mt:If name="datebased_archive">
002: <mt:ArchivePrevious><link rel="prev" href="<$mt:ArchiveLink$>" title="<$mt:ArchiveTitle encode_html="1"$>" /></mt:ArchivePrevious>
003: <mt:ArchiveNext><link rel="next" href="<$mt:ArchiveLink$>" title="<$mt:ArchiveTitle encode_html="1"$>" /></mt:ArchiveNext>
004:</mt:If>
005:<mt:If name="archive_class" eq="category-archive">
006: <link rel="alternate" type="application/atom+xml" title="Category Atom" href="<mt:BlogArchiveURL /><mt:SubCategoryPath />/atom.xml" />
007:</mt:If>
008:</head>
...後略...
P.582
フィードのリンクを各カテゴリページに表示する
「購読」ウィジェットテンプレート(サンプルテンプレート)
<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>
<mt:if name="archive_class" eq="category-archive">
<p><a href="<mt:blogArchiveURL /><mt:subCategoryPath />/atom.xml" /><img src="<mt:staticWebPath />plugins/SampleTemplateSet/images/feed-icon-32x32.jpg" width="32" height="32" alt="Feed アイコン" title="このカテゴリを購読" /></a><a href="<mt:blogArchiveURL /><mt:subCategoryPath />/atom.xml" />このカテゴリを購読</a></p>
</mt:if>
</dd>
「スタイルシート」インデックステンプレート(サンプルテンプレート)
...前略...
.syndicate p {
margin-bottom: 3px; ←フィードのリンクの下マージンを設定します
}
...後略...
★「購読」ウィジェットテンプレート(デフォルトテンプレート)
追加箇所は5~7行目です。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>
<mt:If name="archive_class" eq="category-archive">
<li><img src="<$mt:StaticWebPath$>images/status_icons/feed.gif" alt="購読する" width="9" height="9" /> <a href="<$mt:BlogArchiveURL$><$mt:SubCategoryPath$>/atom.xml" />このカテゴリを購読</a></li>
</mt:If>
<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>