【问题标题】:How to add a image url to feed as a item child?如何添加图像 url 以作为项目子项提供?
【发布时间】:2026-02-12 09:35:01
【问题描述】:

有没有办法将缩略图网址添加到 wordpress 提要??

我知道如何将缩略图添加到 the_content,但我需要 rss 提要在另一个域上布局页面。所以我只是想使用 $item->get_title(), $item->get_description() 和缩略图像 $item->get_image_url

在其他 domain.com 上我使用以下(其他 domain.com 也是 WP 安装)

require( '../../../site/wp-load.php' );
include_once(ABSPATH . WPINC . '/feed.php');
$rss= fetch_feed('domain.com/feed/?post_type=recipes');
foreach($rss->get_items() as $item) {

    echo $item->get_title().'<br/>'.$item->get_description();
    echo '<hr/>';

}

有什么建议吗?

【问题讨论】:

    标签: image wordpress feed


    【解决方案1】:

    如果你想要图片 url (src)

    您必须先使用get_post_thumbnail_id 获取拇指ID,然后使用wp_get_attachment_image_src 获取图像src

    <?php
    $post_thumbnail_id = get_post_thumbnail_id( $post_id );
    $image_src = wp_get_attachment_image_src( $post_thumbnail_id , $size, $icon ); 
    ?>
    

    【讨论】:

    • tx 但是是的,我试过了。这是主要用于将图像添加到 rss-feed $item->descreption 的函数。在我的情况下,我想我喜欢向简单的 添加一个节点,例如 。如果我理解正确,WP 使用某种 simplepie 格式作为 rss 提要,但我没有包含图像,所以看起来。我试过 get_image_url ();
    • 啊,好吧,我知道你要去哪里了,我有 $image_src = wp_get_attachment_image_src( $post_thumbnail_id, 'full' ); 的原始 img src,但我仍然不知道如何使用 add_filter('the_content_feed', 'rss_post_thumbnail');function rss_post_thumbnail($content) {global $post;if( has_post_thumbnail($post-&gt;ID) ) $post_thumbnail_id = get_post_thumbnail_id($post-&gt;ID); $image_src = wp_get_attachment_image_src($post_thumbnail_id, 'full'); //where to put $image_src[0] in the rss feed? $content = '&lt;p&gt;'.$image_src[0].'&lt;/p&gt;'.$content;return $content; } 将此网址放入 rss 提要中跨度>
    • 您能否在上次更新时编辑您的问题,因为评论中的代码不可读:)
    • 您好 Bouchaala,嗯,不能再编辑了。我喜欢完成的是将$image_src = wp_get_attachment_image_src($post_thumbnail_id, 'full'); 的值添加为 rss 提要中的单独节点,而不是作为内容节点的一部分。
    • 仅供参考:我现在正在编辑 wp-includes/feed-rss2.php,尽管我想将其添加到 functions.php 并保持 feed-rss2.php 不变。
    最近更新 更多