Jump to content

RSS feed item showing twice


Marvin0410

Recommended Posts

Hey all,

 

I'm currently making myself a blog website from scratch. It's sort of my personal project; I'm using it to get a feel for PHP (and it'd look great on my resume!).

 

Anyway, I'm using the following PHP code to get the items from my RSS feed, and display them. Problem is, my first item shows twice! I'm thinking it's a problem with my loop, but I'm not sure. Any ideas:

 

My PHP code to render my RSS is as follows:

 

<?php

//Purpose: This loads the XML document using the DOMParser, and mixes it w/ HTML to style and format it.

try

{

$xmldoc = new DOMDocument();

$xmldoc->load('test_RSS_feed.xml');

$content = null; //HTML mixed with XML results go here

$allitems = $xmldoc->getElementsByTagName('item');

foreach ($allitems as $item)

{

//get ALL instances of wanted element(s)

$titles = $item->getElementsByTagName('title');

$dates = $item->getElementsByTagName('pubDate');

$descriptions = $item ->getElementsByTagName('description');

 

//will include the CSS classes for these eventually!

$content.= ('

<ul class ="blog_entry">

<li class="title_entry">

'.$titles->item(0)->nodeValue.

  '</li>

<li class="date_entry">

'.$dates->item(0)->nodeValue.

'</li>

<br>

<li class="description_entry">

'.$descriptions->item(0)->nodeValue.

  '</li>

</ul>

<br><br><br>');

echo $content;

}

}

catch(Exception $e)

{

echo $e->getMessage();

}

?>

 

And the XML in my RSS feed is as follows:

 

 

<?xml version= "1.0" encoding = "UTF-8" ?> <!--Every XML doc starts with this -->

<?xml-stylesheet type="text/css" href="sample_xml_css.css" ?> <!--stylesheet for RSS feed-->

<rss version = "2.0">

<channel>

<!--RSS feed information-->

<title>My first RSS feed</title>

<description>This is my first foray into RSS. I may use this to create a blog!</description>

<lastBuildDate>Mon, Oct. 11, 2010 13:13:26 GMT</lastBuildDate> <!--date format complies to different standards-->

<webMaster>mserrano0410@gmail.com</webMaster> <!--has email of webmaster-->

<item>

<title>My first item; this is the title.</title>

<link>http://www.example.com/sample_item.html</link> <!--provides a link to the RSS item; required-->

<pubDate>Mon, Oct 11, 2010 13:15:20 GMT</pubDate> <!--Every date complies to formatting standards-->

<description>We are now inside of an item; this is a description tag.</description>

</item>

<item>

<title>My second item.</title>

<link>http://www.google.com</link>

<pubDate>Fri, Oct 15, 2010 23:02:40 GMT</pubDate>

<description>This is a second helping of examples biatch!</description>

</item>

<!--can create as many items as you want, but it MUST have:

1) Title

2) Link to item; when clicked, takes you directly to that item. This is a SEPARATE HTML document!

3) Description

-->

</channel>

</rss>

 

Thanks in advance,

Marvin

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.