Я пытаюсь разработать модуль карусели Bootstrap для новостей, которые выходят с удаленного сайта, используя свой RSS-канал для моего веб-сайта Joomla 3.3.3. Это веб-сайт WordPress. Я добавил следующий код для веб-сайта WP теме/functions.phpКак обрабатывать данные RSS, поступающие из WordPress для модуля RSS Joomla?
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');
теперь я могу видеть <myimage>[image_url]</myimage>
линию подачи RSS, когда я смотрю на исходный код.
Но я не знаю, как обращаться с ним в модуле RSS-модуля Joomla (mod_feed).
Я попытался извлечь URL изображения с помощью
$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
выходу как следующий
<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>