Images in RSS feed

后端 未结 6 1279
北海茫月
北海茫月 2020-12-30 22:23

Whenever I see images in an RSS feed, they are embedded in CDATA, rather than surrounded by tags.

In my feed, I would like the images to show up without doing that.<

相关标签:
6条回答
  • 2020-12-30 22:35

    On Colonol Sponsz' hint, I researched:

    There's no image tag for items, only for the channel. So you have to do it via the CDATA tag.

    0 讨论(0)
  • 2020-12-30 22:40

    It works with a seperate tag, as you said. The problem is the specification of version 2.0.

    I know, there are feed reader that does supress images for bandwidth reasons.

    Source: RSS specification 2.0 via Wikipedia

    0 讨论(0)
  • 2020-12-30 22:45

    Use, e.g.:

    <enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" length="12216320" type="audio/mpeg" />
    

    Documentation here

    0 讨论(0)
  • 2020-12-30 22:52

    For completeness: In RSS 2.0, you CAN have a single enclosure inside an item, which per the spec. can be for a single image. However I understand that support among feed aggregators varies. More typically this is used for things like podcasts. The RSS 2.0 standard states:

    <enclosure> is an optional sub-element of <item>. 
    

    It has three required attributes. url says where the enclosure is located, length says how big it is in bytes, and type says what its type is, a standard MIME type. The url must be an http url.

    Note that you must include the size of the item, along with the URL and mime type.

    However, as others indicated, including the picture(s) in CDATA is much more common.

    0 讨论(0)
  • 2020-12-30 22:55

    You can use the media:content element (spec) within item.

    Make sure you declare the MRSS (Media RSS) namespace (the xmlns:media attribute, below) for this element, if it is not declared for the whole RSS feed, as it won't validate otherwise. (E.g., out-of-the-box WordPress.)

        <media:content 
            xmlns:media="http://search.yahoo.com/mrss/" 
            url="http://www.widget.com/images/thumb.gif" 
            medium="image" 
            type="image/jpeg" 
            width="150" 
            height="150" />
    

    This may or may not display as you'd like; you'd have to experiment. Embedding in content is in that way simpler, though this route helps with things like MailChimp integration (h/t this answer) or other custom solutions.

    An example implementation for WordPress is in my answer here.

    0 讨论(0)
  • 2020-12-30 23:02

    I believe you can use <media:content ....> items with good support by most rss readers, it is working flawlessly for us on mailchimp (rss to email newsletter).

    See http://kb.mailchimp.com/article/how-can-i-format-the-image-content-in-my-rss-to-email-campaigns

    EDIT: Here's a live link: https://blog.mailchimp.com/rss-to-email-enhancement-for-publishers/

    0 讨论(0)
提交回复
热议问题