php - 如何在其他 wordpress 网站上显示自定义 wordpress 提要?
问题描述
我正在建立两个 wordpress 网站。我在我的第一个站点上有一个自定义 RSS 提要,我想在我的第二个站点上显示自定义字段。这是特色图片。
我可以像这样显示标准字段“title”或“permalink”:“get_title(); ?>”。但无法显示新字段“图像”。
自定义 RSS 是:
<channel>
<title>TITRE CATEGORIE</title>
<atom:link href="http://127.0.0.1/site/feed/" rel="self" type="application/rss+xml" />
<link>http://127.0.0.1/site</link>
<description>DESCRIPTION</description>
<lastBuildDate>Fri, 05 Jul 2019 13:15:21 +0000</lastBuildDate>
<language>fr-FR</language>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator>https://wordpress.org/?v=5.2.2</generator>
<item>
<title>TITRE</title>
<link>http://127.0.0.1/site/page</link>
<pubDate>Wed, 26 Jun 2019 15:56:57 +0000</pubDate>
<dc:creator><![CDATA[gregory]]></dc:creator>
<category><![CDATA[cat-1]]></category>
<category><![CDATA[cat-2]]></category>
<guid isPermaLink="false">http://127.0.0.1/site/?p=56</guid>
<description><![CDATA[<p>L’article <a rel="nofollow" href="http://127.0.0.1/site/page/">Webserie 1</a> est apparu en premier sur <a rel="nofollow" href="http://127.0.0.1/site">NOM DU SITE</a>.</p>
]]></description>
<content:encoded><![CDATA[<p>L’article <a rel="nofollow" href="http://127.0.0.1/site/page/">TITRE</a> est apparu en premier sur <a rel="nofollow" href="http://127.0.0.1/site">NOM DU SITE</a>.</p>
]]></content:encoded>
<image><![CDATA[http://127.0.0.1/site/wp-content/uploads/2019/07/cookies.jpg]]></image>
</item>
我使用此代码来显示 rss :
<?php if(function_exists('fetch_feed')) {
include_once(ABSPATH . WPINC . '/feed.php');
$feed = fetch_feed('http://127.0.0.1/site/tag/musique/feed/');
$limit = $feed->get_item_quantity(1);
$items = $feed->get_items(0, $limit);
} ?>
<?php foreach ($items as $item) : ?>
<?php echo $item->get_title(); ?>
<?php echo $item->get_permalink(); ?>
<?php echo $item->image; ?>
<?php endforeach; ?>
“图像”字段不显示任何内容...如何定位这行项目?感谢您的帮助\o/
解决方案
您想要获得特色图片,例如:
get_the_post_thumbnail('thumbnail');
添加到您的代码中:
<?php echo $item->get_the_post_thumbnail('thumbnail');?>
推荐阅读
- java - 我正在尝试绘制由 JCheckBox 触发的东西
- okta - 通过 Okta SCIM 应用程序发送组自定义属性
- ubuntu - 从 Ubuntu 的收藏夹中删除文件夹
- angular - 运行 Ionic Application 后动态设置环境变量
- laravel - 使用调用控制器的路由时未识别的控制器
- google-drive-api - Google Drive API:使用不那么可怕的范围编辑共享文件
- powershell - Powershell - 如果文件已存在,则将文件移动旧 x 天并重命名
- python - 如果您在 pandas 数据框中有时间信息,那么使用 np.busday_count 的方法比使用天数更准确吗?
- vba - Access 2003 - 如何显示来自 url 的图像?
- python - Python - 井字游戏 - 计算机总是赢