RSS 提要模板文件中的 WordPress 特色图片 url

WordPress featured image url in RSS feed template file

我已经创建了自定义 RSS 提要模板文件:

<?php
/**
 * RSS 0.92 Feed Template for displaying RSS 0.92 Posts feed.
 *
 * @package WordPress
 */

header( 'Content-Type: ' . feed_content_type( 'rss' ) . '; charset=' . get_option( 'blog_charset' ), true );
$more = 1;

echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>'; ?>

<articles>
<?php
while ( have_posts() ) :
    the_post();
    ?>
    <article>
        <title><?php the_title_rss(); ?></title>
        <teaser><?php the_excerpt_rss(); ?></teaser>
        <description><?php $original = strip_tags(get_the_content_feed('rss2'));
        $stripped = str_replace("&nbsp;", " ", $original);
        echo $stripped; ?></description>
        <link><?php the_permalink_rss(); ?></link>
        <image>http://placehold.it/100x100</image>
        <date><?php 
    echo mysql2date(
        'd-m-Y H:i:s', 
        get_post_time('Y-m-d H:i:s', true), 
        false
    ); 
?></date>
        <?php
        /**
         * Fires at the end of each RSS feed item.
         *
         * @since 2.0.0
         */
        do_action( 'rss_item' );
        ?>
    </article>
<?php endwhile; ?>
</articles>

我有一个问题,我希望它输出特色图片 url 但是 atm。它只是用占位符图像进行了硬编码。

我试过 get_the_post_thumbnail URL 像这样:

<image><?php echo get_the_post_thumbnail_url('full'); ?></image>

然而回声只是空白。

我也在下面尝试过,但它只是回显数组。

<image><?php echo wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?></image>

如何在我的 RSS 提要中回显特色图片 URL?

如果你想使用 get_the_post_thumbnail_url,像这样传递 id 给它:

<image>
   <url><?php echo get_the_post_thumbnail_url(get_the_ID(), 'full'); ?></url>
</image>

或者如果你想使用 wp_get_attachment_image_url,那么你可以这样做:

<image>
   <url><?php echo wp_get_attachment_image_url(get_the_ID(), 'full'); ?></url>
</image>