SimplePie和get_item_tags属性 [英] SimplePie and get_item_tags attribute

查看:67
本文介绍了SimplePie和get_item_tags属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Simplepie解析不同的RSS提要,并将它们传递给Smarty模板,并且我需要从每个示例行中返回该属性,在此示例中,该行显示为:NEWSX

I'm using Simplepie to parse different RSS feeds, passing them to a Smarty template, and I need to return the attribute from each item line that in this example reads: NEWSX

<source url="http://whatever.url/"><![CDATA[NEWSX]]></source>

我发现get_item_tags方法将选择使用以下内容的行和属性:

I have found the get_item_tags method will select the line and attribute having used the following:

$newssource = $item->get_item_tags('','source');

这是我的问题.使用以下代码时,我不知道如何将每个源附加到一个项目上(这样,基本上我可以每次在通常的标题,链接,描述等旁边显示不同的源元素):

Here is my problem. I don't know how to attach each source to an item when using the following code (so that basically I can display the different source element each time alongside the usual title, link, description and so on):

$RSS = array();
foreach($items as $item){
    $feed = $item->get_feed();
    $tmp=array();

    $newssource = $item->get_item_tags('','source');
    echo $newssource[0]["data"];

    if ($feed){
        if ($enclosure = $item->get_enclosure()){
          $tmp['title'] = $item->get_title();
          $tmp['permalink'] = $item->get_permalink();
          $tmp['thumbnail'] = $enclosure->get_thumbnail();
          $tmp['description'] = $enclosure->get_description();
          $tmp['image'] = $enclosure->get_link();
        }
        $tmp['date'] = $item->get_date('j M Y');
        $tmp['content'] = $item->get_content();
        $tmp['title'] = $item->get_title();
        $tmp['link'] = $item->get_link();
        $tmp['description'] = $item->get_description();

        array_push($RSS, $tmp);
    }

}

可以做到吗?在此先感谢您的帮助或建议.

Can it be done? Thanks in advance for any help or advice.

推荐答案

所以这是解决方案:

$RSS = array();
foreach($items as $item){
$feed = $item->get_feed();
$tmp=array();

if ($feed){
    $tmp['date'] = $item->get_date('j M Y, g:i a');
    $tmp['content'] = $item->get_content();
    $tmp['title'] = $item->get_title();
    $tmp['link'] = $item->get_link();
    $tmp['description'] = $item->get_description();
    $tmp['source'] = $item->get_item_tags('','source')[0]["data"];

    array_push($RSS, $tmp);
    }
}

$smarty->assign( $params['assign'], $RSS );

在smarty模板中:

And in the smarty template:

<div class="cont">
    <a href="{$entry.link}" target="_new">{$entry.title}</a>
    <br />
    <span class="date">Published on: <strong>{$entry.date}</strong></span><br />
   <span class="source">Via : <strong>{$entry.source}</strong></span><br />
</div>

这篇关于SimplePie和get_item_tags属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆