collapse

Author Topic: Display rss feed on website using php  (Read 1195 times) Bookmark and Share

0 Members and 1 Guest are viewing this topic.

Offline Car

  • Full Member
  • ***
  • Posts: 200
  • Reputation Power: 0
  • Car has no influence.
  • Gender: Female
    • CHouseLive
  • Referrals: 0
  • Referrals: 0
Display rss feed on website using php
« on: 19 September 2009, 09:25:44 »
Hi guys.

Need a little help again  :)

Okay, I have got my new look website up and running.

Presently I have the main site and then a newsletter for which I am using blogger.

If you look at the right hand column of the main site there is a list called "Newsletter Archives" displaying links to the titles of the last 4 newsletters published on the newsletter blog.

These links are gained using feedreader.  Javascript is being used to populate the links.

Is it possible to have the same thing, except using php.

If it is possible, how would I do this?

Thanks
Cara

Offline ElanMan

  • Jr. Member
  • **
  • Posts: 51
  • Reputation Power: 0
  • ElanMan has no influence.
  • Gender: Male
    • ElanMan's Drawers
  • Referrals: 0
  • Referrals: 0
Re: Display rss feed on website using php
« Reply #1 on: 20 September 2009, 09:08:58 »
If you have the use of SimpleXml, you could do something like this:
Code: [Select]
<?php
$feed 
'your-feed-url-here';
$rss simplexml_load_file($feed);
$i=0;
foreach(
$rss->channel->item as $item)
{
    if (
$i 4)
    {
echo '<a href="'.$item->link.'">'.$item->title.'</a><br />';
    }
    
$i++;
}
?>

Offline Car

  • Full Member
  • ***
  • Posts: 200
  • Reputation Power: 0
  • Car has no influence.
  • Gender: Female
    • CHouseLive
  • Referrals: 0
  • Referrals: 0
Re: Display rss feed on website using php
« Reply #2 on: 20 September 2009, 09:21:51 »
If you have the use of SimpleXml, you could do something like this:
Code: [Select]
<?php
$feed 
'your-feed-url-here';
$rss simplexml_load_file($feed);
$i=0;
foreach(
$rss->channel->item as $item)
{
    if (
$i 4)
    {
echo '<a href="'.$item->link.'">'.$item->title.'</a><br />';
    }
    
$i++;
}
?>

Oh Wow.  This is absolutely brilliant.  Thank you!

Offline Car

  • Full Member
  • ***
  • Posts: 200
  • Reputation Power: 0
  • Car has no influence.
  • Gender: Female
    • CHouseLive
  • Referrals: 0
  • Referrals: 0
Re: Display rss feed on website using php
« Reply #3 on: 29 March 2010, 06:16:35 »
I wonder if Elanman is still around, or perhaps someone else can help me :) This little snippet he gave me works superbly however I was wondering if it is possible to include more.  Specifically the first 200 characters of the post as well as the date on which the blog was posted.

Offline ElanMan

  • Jr. Member
  • **
  • Posts: 51
  • Reputation Power: 0
  • ElanMan has no influence.
  • Gender: Male
    • ElanMan's Drawers
  • Referrals: 0
  • Referrals: 0
Re: Display rss feed on website using php
« Reply #4 on: 29 March 2010, 23:22:51 »
Hey up :)
If you want to display the first 200 characters of the post, use
Code: [Select]
substr($item->description,0 ,200)and for the date, use
Code: [Select]
$item->pubDatebut aren't your posts titled with the date anyway?...
So replace your previous echo with something like:
Code: [Select]
echo '<p><a href="'.$item->link.'">'.$item->title.'</a><br />'.$item->pubDate.'<br />'.substr($item->description,0 ,200).'</p>';Hope that helps :)

Offline Car

  • Full Member
  • ***
  • Posts: 200
  • Reputation Power: 0
  • Car has no influence.
  • Gender: Female
    • CHouseLive
  • Referrals: 0
  • Referrals: 0
Re: Display rss feed on website using php
« Reply #5 on: 31 March 2010, 22:04:12 »
Hi Em
You have an exceptional memory, yes the original blog you helped me with were titled with the date... it acts as a news letter.  I want to use the code for a different project.
Thanks a million. 

 


* Featured Tutorials