{"id":798,"date":"2012-09-09T18:48:12","date_gmt":"2012-09-10T01:48:12","guid":{"rendered":"http:\/\/blog.avatarplanet.com\/?p=798"},"modified":"2012-09-09T18:48:12","modified_gmt":"2012-09-10T01:48:12","slug":"display-rss-feeds-on-your-webpage","status":"publish","type":"post","link":"https:\/\/www.avatarplanet.com\/blog\/2012\/09\/09\/display-rss-feeds-on-your-webpage\/","title":{"rendered":"Display RSS feeds on your webpage"},"content":{"rendered":"<p>Someone asked me this week how I display RSS feeds from three external sources on my personal website <a href=\"http:\/\/ErikBainbridge.com\">ErikBainbridge.com<\/a> if it\u2019s not a WordPress website.\u00a0 WordPress after all offers a convenient function, RSSImport(), for reading RSS feeds on a WordPress webpage, but there is no equivalent function that I\u2019m aware of for non-Wordpress webpages.<\/p>\n<p>The answer is that I cheated.\u00a0 Although <a href=\"http:\/\/ErikBainbridge.com\">ErikBainbridge.com<\/a> doesn\u2019t appear to be a WordPress website, it actually is.\u00a0 I\u2019m just not using a Theme and I don\u2019t have a blog on that website.\u00a0 I simply built WordPress into it so I would have access to RSSImport().<\/p>\n<p>It\u2019s a solution that works, but building a website with WordPress underlying it is a lot of work just to have easy access to RSS feeds.\u00a0 Is there an easier way?<br \/>\n<script type=\"text\/javascript\">\/\/ <![CDATA[\ngoogle_ad_client = \"ca-pub-7037687646021923\"; \/* baner 468x60 *\/ google_ad_slot = \"5806720043\"; google_ad_width = 468; google_ad_height = 60;\n\/\/ ]]><\/script><br \/>\n<script type=\"text\/javascript\" src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\/\/ <![CDATA[\n\n\n\/\/ ]]><\/script><\/p>\n<p>Yes, there is, and I use it on my <a href=\"http:\/\/AvatarPlanet.com\">AvatarPlanet.com<\/a> website, where I display the three most recent posts from my Avatar Planet blog.\u00a0 I could display RSS feeds from any website, not just my own.\u00a0 It\u2019s equally as capable as using RSSImport(), and the way I did it is actually easier to implement as long as you don\u2019t mind dealing with a few lines of PHP.<\/p>\n<p>Before I start, there are several caveats you need to be aware of.\u00a0 In order for this to work, your PHP implementation needs to have PEAR and XML_Parser installed, and allow_url_fopen must be set to \u201cON\u201d.\u00a0 Unless you are the system administrator, you probably won\u2019t have control over either of these.\u00a0 Assuming that your system is configured this way, \u00a0you should be able to fairly easily display RSS feeds on your webpage.<\/p>\n<p>The following is how I did it on <a href=\"http:\/\/avatarplanet.com\">avatarplanet.com<\/a> to read feeds from my blog, <a href=\"http:\/\/blog.AvatarPlanet.com\">blog.AvatarPlanet.com<\/a> and to display the three most recent posts.\u00a0 The output is in the form of a bulleted (unordered) list in which every line is the headline from the RSS feed that you can click to read the full post :<\/p>\n<p>&lt;?php<br \/>\nrequire_once &#8220;XML\/RSS.php&#8221;;<\/p>\n<p>$rss =&amp; new XML_RSS(&#8220;http:\/\/blog.avatarplanet.com\/?feed=rss&#8221;);<br \/>\n$rss-&gt;parse();<\/p>\n<p>echo &#8220;&lt;ul&gt;&#8221;;<br \/>\n$number_posts=3;<br \/>\nforeach ($rss-&gt;getItems() as $item) {<br \/>\n&nbsp;&nbsp;&nbsp;if (++$i &lt;= $number_posts) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &#8220;&lt;li&gt;&lt;a href=\\&#8221;&#8221; . $item[&#8216;link&#8217;] . &#8220;\\&#8221;&gt;&#8221; . $item[&#8216;title&#8217;] . &#8220;&lt;\/a&gt;&lt;\/li&gt;&lt;br&gt;&#8221;;<br \/>\n&nbsp;&nbsp;&nbsp;}<br \/>\n}<br \/>\necho &#8220;&lt;\/ul&gt;&#8221;;<br \/>\n?&gt;<br \/>\nIf you haven\u2019t written PHP before, here are a few basics you need to know:<\/p>\n<ol>\n<li>You insert these lines into your HTML file.\u00a0 In order for them to work, you\u2019ll\u00a0 need to change the filename\u2019s extension from .html or .htm to .php.\u00a0 Be sure to remove the old file from the directory, or there may be unpredictable results, especially if the file is named index.htm or index.html.<\/li>\n<li>You should copy the above lines of PHP and paste them into your HTML where you want it displayed.<\/li>\n<li>\u201c&lt;?php\u201d and \u201c?&gt;\u201d are opening and closing tags that mark the lines as PHP rather than HTML.<\/li>\n<li>You need to copy and paste these lines exactly as they appear here.<\/li>\n<\/ol>\n<p>There are only two changes you need to make, other than formatting changes (for example if you don&#8217;t want it to appear as a bulleted list):<\/p>\n<ol>\n<li>Change \u201cblog.avatarplanet.com\/?feed=rss\u201d to the url of whatever RSS feed you want.\u00a0 For example, if you wanted the New York Times home page RSS feed, you would use the url \u201crss.nytimes.com\/services\/xml\/rss\/nyt\/HomePage.xml\u2019.<\/li>\n<li>This example displays the three most recent items in the RSS feed.\u00a0 If you want a different number, change the number 3 in the line <em>\u201c$number_posts=3\u201d <\/em>to whatever number you want.<\/li>\n<\/ol>\n<p>If you want to display RSS feeds from more than one url, just repeat everything in the above code except the line containing &#8220;require_once &#8220;XML\/RSS.php&#8221;;&#8221;\u00a0 All you have to change is the url.<\/p>\n<p>I can\u2019t guarantee this method of displaying RSS feeds will work for you, but as long as your system is configured the way I described above, it should work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Someone asked me this week how I display RSS feeds from three external sources on my personal website ErikBainbridge.com if it\u2019s not a WordPress website.\u00a0 WordPress after all offers a convenient function, RSSImport(), for reading RSS feeds on a WordPress webpage, but there is no equivalent function that I\u2019m aware of for non-Wordpress webpages. The &hellip; <a href=\"https:\/\/www.avatarplanet.com\/blog\/2012\/09\/09\/display-rss-feeds-on-your-webpage\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Display RSS feeds on your webpage&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[113,116,118],"class_list":["post-798","post","type-post","status-publish","format-standard","hentry","category-report","tag-php","tag-programming","tag-rss"],"_links":{"self":[{"href":"https:\/\/www.avatarplanet.com\/blog\/wp-json\/wp\/v2\/posts\/798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.avatarplanet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.avatarplanet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.avatarplanet.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.avatarplanet.com\/blog\/wp-json\/wp\/v2\/comments?post=798"}],"version-history":[{"count":0,"href":"https:\/\/www.avatarplanet.com\/blog\/wp-json\/wp\/v2\/posts\/798\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.avatarplanet.com\/blog\/wp-json\/wp\/v2\/media?parent=798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.avatarplanet.com\/blog\/wp-json\/wp\/v2\/categories?post=798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.avatarplanet.com\/blog\/wp-json\/wp\/v2\/tags?post=798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}