douyun3631 2019-02-15 09:11
浏览 48

SimpleXML Rss Feed如何使用PHP将图像解析为Smarty模板?

Hi I have a simplexml feed from a WP Blog working, but can't seem to get the image passed with the link.

I've pasted what I have in both *.php and *.tpl files below. I've tried quite a few ways, but can't seem to get it to show the image as the image source remains empty in html Can anyone help with code that works? I have this in the PHP code:

    public function hookDisplayFooter($params)
{
    // Conf
    $title = strval(Configuration::get('RSS_FEED_TITLE'));
    $url = strval(Configuration::get('RSS_FEED_URL'));
    $nb = (int) (Configuration::get('RSS_FEED_NBR')) ? (int) (Configuration::get('RSS_FEED_NBR')) : 5;



    $cacheId = $this->getCacheId($this->name . '|' . date("YmdH"));
    if (!$this->isCached($this->templateFile, $cacheId)) {
        $rss_links = array();
        if ($url && ($contents = Tools::file_get_contents($url))) {
            try {
                $xml = new SimpleXMLElement($contents);
                $loop = 0;
                if (!empty($xml->channel->item)) {
                    foreach ($xml->channel->item as $item) {
                        if (++$loop > $nb) {
                            break;
                        }
                        $rss_links[] = (array)$item;
                    }
                }
            } catch (Exception $e) {
                Tools::dieOrLog($this->trans('Error: invalid RSS feed in "%module_name%" module: %message%', array('%module_name%' => $this->name, '%message%' => $e->getMessage()), 'Modules.Rssfeed.Admin'));
            }
        }



        $this->smarty->assign(array(
            'title' => ($title ? $title : $this->trans('RSS feed', array(), 'Modules.Rssfeed.Admin')),
            'rss_links' => $rss_links
        ));
    }

    return $this->fetch($this->templateFile, $cacheId);
}

And this in the Smarty tpl file:

  <div>
{if $rss_links}
  <ul>
    {foreach from=$rss_links item='rss_link'}
    <div><img src="{$rss_link['image']}" width="50px" height="50px" ></div>
      <li><div><a href="{$rss_link['link']}" title="{$rss_link['title']}" target="_blank">{$rss_link['title']} </a></li>
    <a href="{$rss_link['link']}" class="more-blog">Continue Reading ></a></li><p> </p>
    {/foreach}
        </ul></div>
{else}
  <p>{l s='No RSS feed added' d='Shop.Theme.Catalog'}</p>
{/if}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 chaquopy python 安卓
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 有没有帮写代码做实验仿真的
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥30 vmware exsi重置后登不上
    • ¥15 易盾点选的cb参数怎么解啊
    • ¥15 MATLAB运行显示错误,如何解决?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题