特定サイトのrssを読み込ませて表示する ー jQuery編

  • 作成日:2015-6-4

サイトに特定サイトのRSSフィードを読み込みたいがあります。こういう場合は、「zRSSFeed」というjQueryプラグインを使用します。 zrssfeed_top

導入は簡単3ステップで完了します。

zRSSFeed本体をダウンロード

以下のダウンロードサイトより、最新版のファイル(zip)をダウンロードします。  RSS Feeds Reader Plugin for jQuery – Zazar Online Website Builder

執筆時点のバージョンは1.2.0で、こちらからダウンロードできます。

このファイルを解凍して出てきたファイルから、jquery.zrssfeed.min.jsというファイルを取り出し、ヘッダーに以下のとおりに記述を追加します。

header.phpに挿入

以下のコーディングをheader.phpの</head>より以前に挿入してください。

&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"&gt;&lt;/script&gt;
&lt;script type='text/javascript' src='js/jquery.zrssfeed.min.js'&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;// &lt;![CDATA[ $(document).ready(function () { $('#test').rssfeed('http://example.com/feed/', { limit: 5,content: false }); }); // ]]&gt;
&lt;/script&gt;

※6行目に次項に示すパラメータを追加することにより、RSSFeedの形式を変更することができます。

挿入タグを記事に追加

読み込ませたいpost記事や固定ページの部分に以下のコーディングを追加してください。 挿入はビジュアル画面ではなく、テキストでおこなってください



&lt;div id="test"&gt;&lt;/div&gt;


※上記のdiv要素のid名testに挿入してます。#testは適宜修正して使ってください

サンプル

RSS Feed作成パラメータ

ParameterDefaultDescription
limit10The number of feeds to return (maximum 100).
offset1The feed item number to start at.
headertrueIf true, includes the header section containing the feed name and link.
titletagh4Specifies the HTML tag for the feed title.
datetrueIf true, includes the feed date section.
dateformatdatetimeThe format of feed dates: ‘datetime’ – full date and time, ‘date’ – date only, ‘time’ – time only, ‘timeline’ – lasped time or a format mask (‘dd/MM/yyyy hh:mm:ss’).
contenttrueIf true, includes the feed description.
snippettrueIf true, shows a short description for the feed item, otherwise the full content is displayed.
mediatrueIf true, displays media items when available.
showerrortrueIf true, and an error is returned from the Google Feeds API, the error message is shown.
errormsgReplaces the default friendly message when an error occurs.
keynullOptionally use a Google API key.
sslfalseSupport for SSL. Set to True when using secure pages.
linktarget_selfSpecifies the target for all feed links (‘_blank’, ‘_self’, ‘_top’, framename).
linkredirectSpecifies a page to redirect the feed links to. The original link is contained in the URL parameter named ‘link’.
linkcontentfalseIf true, displays the content of the feed item as a link.
sortSorts the feed items by either ‘title’ or ‘date’. Leave empty for no sorting.
sortasctrueSpecifies the sort direction, either ascending (true) or descending (false).
historicalfalseIf true, returns any additional historical records that may exist.

”This API is no longer available.”の表示について

2015年12月2日追記 このJqueryは、Google APIが削除されたことにより廃止となってしました。別の方法を検討するしかないようです。作者のページには以下の記載があります。

Due to the Google Feeds API being removed from service, which the plugin replied on, it will no longer be available or supported.
スポンサーリンク

ランキング

記事連動目次

※右側の記事と連動したインデックスです。見たいインデックスをクリックしてください。
ページ上部へ戻る