简体   繁体   English

RSS-同时显示pubDate和dc:date

[英]Rss - Show both pubDate and dc:date same function

I have 4 rss feed in the same website. 我在同一网站上有4个RSS提要。 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. 2个rss供稿具有pubDate,其他2个具有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. 因此,如果我将pubDate更改为dc:date 2,其他的将显示“ 1970-01-01”,并且如果我将dc:date更改为pubDate,我将会得到相同的结果,但反之亦然。

Now my question is what is the easiest way to "edit" the function so i can run both types? 现在我的问题是“编辑”功能以便我可以同时运行两种类型的最简单方法是什么?

Get the two of them. 得到他们两个。 If one equals timestamp 0 (1970-01-01), select other one. 如果一个等于时间戳0(1970-01-01),则选择另一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM