Question

I have 4 rss feed in the same website. My function looks like this:

    //-- get_rss     ----------------------------------------------------------------------------------
   //   Returns the RSS feed in LI elements
   //   @param $url (feed url) is recieved from page template
  //    @param $lang (possibillity to declare language if available) is recieved from page template
  //---------------------------------------------------------------------------------------------

function get_rss($url, $lang, $articles) {
$rss = new rss_php;
$rss->load($url);
$items = $rss->getItems();

// Sets the maximum items to be listed
$max_items = $articles;

$count = 0;

$html = '';
// Translates months to swedish
foreach($items as $index => $item) {
$pubdateForeignString = substr($item['pubDate'], 4);
$pubdateEnglishString = str_replace(array('maj', 'okt'), array('may', 'oct'), $pubdateForeignString);
$pubdate = date("Y-m-d", strtotime($pubdateEnglishString));

$html .= '
<ul class="rssList">
<li class="itemTitle"><a href="'.$item['link'].'" title="'.$item['title'].'" rel="external"><h2>'.$item['title'].'</h2></a></li>
<li class="itemText">'.$item['description'].'</li>
<li class="itemLink"><a href="'.$item['link'].'" title="'.$item['title'].'" rel="external" class="readmore">Läs mer</a><em>Publicerad: '.$pubdate.'</em></li>
</ul>';
$count++; //Increase the value of the count by 1
if($count==$max_items) break; //Break the loop is count is equal to the max_loop
}    
echo $html;
 }

2 rss-feeds have pubDate and the 2 other have dc:date. So if i change pubDate to dc:date 2 works and the others will show "1970-01-01" and if i change dc:date to pubDate ill get the same thing but the other way.

Now my question is what is the easiest way to "edit" the function so i can run both types?

Was it helpful?

Solution

Get the two of them. If one equals timestamp 0 (1970-01-01), select other one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top