【问题标题】:WordPress RSS list add featured image linkWordPress RSS 列表添加精选图片链接
【发布时间】:2016-03-17 20:36:58
【问题描述】:

我想要wordpress post rss列表特色图片链接

例如:

<title>Test title</title>
<desc>Test desc</desc>
<image>imagelink</image>

我没有使用插件。

谢谢

【问题讨论】:

    标签: wordpress rss


    【解决方案1】:

    这样就可以了。将其添加到functions.php 文件中:

    // add the namespace to the RSS opening element
    
    add_action( 'rss2_ns', 'custom_prefix_add_media_namespace' );
    
    function custom_prefix_add_media_namespace() {
        echo "xmlns:media="http://search.yahoo.com/mrss/"n";
    }
    
    // add the requisite tag where a thumbnail exists
    add_action( 'rss2_item', 'custom_prefix_add_media_thumbnail' );
    
    function custom_prefix_add_media_thumbnail() {
        global $post;
        if( has_post_thumbnail( $post->ID )) {
            $thumb_ID = get_post_thumbnail_id( $post->ID );
            $details = wp_get_attachment_image_src($thumb_ID, 'thumbnail');
            if( is_array($details) ) {
                echo '<media:thumbnail url="' . $details[0] . '" width="' . $details[1] . '" height="' . $details[2] . '" />';
            }
        }
    }
    

    此外,当您添加此内容时,请务必通过转到“设置”>“永久链接”来重置永久链接(刷新它们),然后将永久链接更改为默认值,然后返回到您定义的设置,或者只是重新保存。

    然后,检查您的提要,媒体应该在那里。

    【讨论】:

      猜你喜欢
      • 2012-02-25
      • 2022-12-11
      • 1970-01-01
      • 2015-03-09
      • 2012-12-23
      • 2015-11-01
      • 2022-07-20
      • 1970-01-01
      • 2021-12-29
      相关资源
      最近更新 更多