guzzlemett Posted October 18, 2016 Share Posted October 18, 2016 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. Quote Link to comment Share on other sites More sharing options...
guzzlemett Posted October 24, 2016 Author Share Posted October 24, 2016 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.