我正在尝试开发Bootstrap的旋转木马模块,用于通过我的Joomla 3.3.3网站的RSS源从远程网站获取新闻。这是一个WordPress网站。我已将以下代码添加到WP网站 theme / functions.php
function zkanoca_add_image_to_rss() {
$thumb_id = get_post_thumbnail_id( get_the_ID() );
if ( ! empty( $thumb_id ) ) {
echo '<myimage>' . wp_get_attachment_url( $thumb_id ) . '</myimage>';
}
}
add_action('rss2_item', 'zkanoca_add_image_to_rss');
add_action('rss_item', 'zkanoca_add_image_to_rss');
当我查看源代码时,我现在可以在rss Feed中看到<myimage>[image_url]</myimage>
行。
但我不知道如何在Joomla的RSS feed模块(mod_feed)上处理它。
我尝试使用
提取图片网址 $feed[$i]->myimage;
在循环中就像$feed[$i]->title;
一样,但没有效果。
我为某个项目调用var_dump()
函数,但无法看到<myimage>
信息的关键元素。
我找到 /libraries/joomla/feed/parser/rss.php ,然后添加了
protected function handleMyimage(JFeed $feed, SimpleXMLElement $el) {
$feed->myimage = (string) $el;
}
之后,我修改了 /libraries/joomla/feed/feed.php
// /libraries/joomla/feed/feed.php
protected $properties = array(
'uri' => '',
'title' => '',
'updatedDate' => '',
'description' => '',
'categories' => array(),
'contributors' => array(),
'myimage' => '' //added this key
);
然后我添加了
// /libraries/joomla/feed/link.php line 60s
public $myimage;
进入JFeedLink
类并修改
// /libraries/joomla/feed/link.php line 90s
public function __construct($uri = null, $relation = null, $type = null, $language = null, $title = null, $length = null ) {
$this->uri = $uri;
$this->relation = $relation;
$this->type = $type;
$this->language = $language;
$this->title = $title;
// Validate the length input.
if (isset($length) && !is_numeric($length)) {
throw new InvalidArgumentException('Length must be numeric.');
}
$this->length = (int) $length;
}
到
// /libraries/joomla/feed/link.php line 90s
public function __construct($uri = null, $relation = null, $type = null, $language = null, $title = null, $length = null, /* added this */ $myimage = null /**/) {
$this->uri = $uri;
$this->relation = $relation;
$this->type = $type;
$this->language = $language;
$this->title = $title;
$this->myimage = $myimage; //added this line too
// Validate the length input.
if (isset($length) && !is_numeric($length)) {
throw new InvalidArgumentException('Length must be numeric.');
}
$this->length = (int) $length;
}
/libraries/joomla/feed/link.php 中的
a的输出如下
<item>
<title>Title here</title>
<link>http://example.com/?p=112</link>
<comments>http://example.com/?p=112#comments</comments>
<pubDate>Fri, 08 Aug 2014 06:05:56 +0000</pubDate>
<dc:creator><![CDATA[Creator Information here]]></dc:creator>
<category><![CDATA[General]]></category>
<category><![CDATA[Arts]]></category>
<guid isPermaLink="false">http://example.com/?p=112</guid>
<description><![CDATA[ some text here […]]]></description>
<content:encoded><![CDATA[more text here]]></content:encoded>
<wfw:commentRss>http://example.com/?feed=rss2&p=112</wfw:commentRss>
<slash:comments>0</slash:comments>
<myimage>http://example.com/wp-content/uploads/2014/08/013.jpg</myimage>
</item>
答案 0 :(得分:0)
我差不多要成功完成它了:) 我忘了在 /libraries/joomla/feed/parser/rss.php
中添加一行protected function processFeedEntry(JFeedEntry $entry, SimpleXMLElement $el) {
$entry->uri = (string) $el->link;
$entry->title = (string) $el->title;
$entry->publishedDate = (string) $el->pubDate;
$entry->updatedDate = (string) $el->pubDate;
$entry->content = (string) $el->description;
$entry->guid = (string) $el->guid;
$entry->comments = (string) $el->comments;
//this line
$entry->myimage= (string) $el->myimage;
现在,我的问题已经消失了。