簡體   English   中英

RSS-同時顯示pubDate和dc:date

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

我在同一網站上有4個RSS提要。 我的函數如下所示:

    //-- 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供稿具有pubDate,其他2個具有dc:date。 因此,如果我將pubDate更改為dc:date 2,其他的將顯示“ 1970-01-01”,並且如果我將dc:date更改為pubDate,我將會得到相同的結果,但反之亦然。

現在我的問題是“編輯”功能以便我可以同時運行兩種類型的最簡單方法是什么?

得到他們兩個。 如果一個等於時間戳0(1970-01-01),則選擇另一個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM