web:modx:revolution:makerssfeed
RSSフィードの作成
RSSフィードの作成にはgetResourcesを使用します。
RSSフィード用ページの作成
- 新しいドキュメントを作成して、タイトルとAliasを設定します。
- 使用テンプレートを(empty)に変更します。
- ページ設定タブに移動して、コンテンツタイプをRSSに変更します。
- 以下をリソースコンテンツに貼り付けます。
<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel> <title>[[*pagetitle:htmlent]]</title> <link>[[~[[*id]]? &scheme=`full`]]</link> <description>[[*introtext:cdata]]</description> <language>[[++cultureKey]]</language> <ttl>120</ttl> <atom:link href="[[~[[*id]]? &scheme=`full`]]" rel="self" type="application/rss+xml" /> [[getResources? &tpl=`rssItem_tpl` &parents=`29,41` &depth=`5` &limit=`10` &includeContent=`1` &includeTVs=`1` &showHidden=`0` &hideContainers=`1` ]] </channel> </rss>
getResourcesのテンプレートの作成
前述のコードで getResources は rssItem_tpl というテンプレートを参照していますので、rssItem_tpl と言う名前でchunkを作成します。
テンプレートの中身は以下の通りです。
<item> <title>[[+pagetitle:htmlent]]</title> <link>[[++site_url]][[~[[+id]]]]</link> <description> [[+introtext:default=`[[+content:ellipsis=`600`]]`:cdata]] </description> <pubDate>[[+publishedon:strtotime:date=`%a, %d %b %Y %H:%M:%S +0900`]]</pubDate> <guid isPermaLink="false">[[++site_url]][[~[[+id]]]]</guid> <dc:creator> [[+createdby:userinfo=`fullname`]] </dc:creator> </item>
- タイトルはpagetitleが使用されています
- Linkはリソースを指しています。
- descriptionはintrotextですが、デフォルトではコンテンツの先頭600文字が使用されます
- 日付は公開日を使用しています。
- GUID はリソースを指しています。
Linkの作成
以下の行をheaderに追加することで、RSSアイコンがアドレスバーに表示されます。
<link rel="alternate" type="application/rss+xml" title="RSSフィード" href="[[~52]]" />
実際に使用しているのが、こちらの株式会社ルーキー/RSS フィード、ルーキータッチ/RSSフィードページです
web/modx/revolution/makerssfeed.txt · 最終更新: 2017/04/14 05:21 by 127.0.0.1