Jump to content

SimplePie: how do I use the get_item_tags element from an RSS feed in a smarty template


guzzlemett

Recommended Posts

From an RSS feed, using SimplePie I'm trying to access the value of the additional element 'source' using 'get_item_tags', and then use this alongside the usual title, description and so on for each item to be displayed in a news page using a smarty template.
 
Problem is that I can't access and convert 'news_source' into an item, instead of using the echo method as stated in the simplepie documentation. When adding as $tmp['news_source'] nothing is being returned. Code snippet follows:
 
$RSS = array();
	foreach($items as $item){
	$feed = $item->get_feed();
	$tmp=array();

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

	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['news_source'] = $item->$get_news_source();

	array_push($RSS, $tmp);
	}
}

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

Then in the smarty template, the output:

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

Thanks for any help or advice.

 

Link to comment
Share on other sites

Have been given the solution, the code is now simplified to the following:

$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 );

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>
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.