Textpattern CMS support forum
Add image to feeds
csb_feed_image still works to add an article image to a feed. It relies on
upm_article_image being installed to add multiple images. I haven’t tried multiple images but with a single article image, I find it puts the image inline with the body or excerpt which doesn’t look good.
So now that
images takes care of things that were only plugin realm previously, could Textpattern give an option to output an article image, or even multiple images?
Also, could there possibly be an option to output
Filed under: cat1, cat2? It does it in some readers with Atom, so perhaps it’s an Atom or feed reader issue, I don’t know.
Also, could there be an option to output both
Re: Add image to feeds
Short of writing a tiny plugin to extend the current feeds (there are hooks that can be used to customize them), you can construct your own feeds if you like. I’ve not really delved into it much, but there’s nothing to stop you doing something like this:
Step 1: register a feed type
- Visit Prefs->Admin panel
- Ensure Advanced options is on
- Visit the ‘Advanced options’ area in prefs
- In the Custom form template types add a new type to output feeds:
[xml] mediatype="application/atom+xml" title="Feed"
Save the changes.
Step 2: Craft your feed
- Visit Presentation>Forms
- Create a new Form
- Select its type as Feed
- Give it a name such as
- Save it
Now create your feed content in that form. Maybe something like this:
<feed xml:lang="" xmlns="http://www.w3.org/2005/Atom"> <title type="text"><txp:site_name/></title> <subtitle type="text"><txp:site_slogan/></subtitle> <link rel="self" href="<txp:site_url />/feed/" /> <id>Some cleverness here</id> <generator uri="https://textpattern.com/" version="4.8.1">Textpattern</generator> <updated><txp:article_custom section="articles" limit="1"><txp:modified format="%Y-%m-%dT%H:%M:%SZ" /></txp:article_custom></updated> <author><name>Stef Dawson</name> <uri>https://example.org/</uri> </author> <txp:article_custom section="articles" limit="10" wraptag="entry"> <author><name><txp:author /></name></author> <published><txp:posted format="%Y-%m-%dT%H:%M:%SZ" /></published> <updated><txp:modified format="%Y-%m-%dT%H:%M:%SZ" /></updated> <title type="html"><txp:title />n</title> <link rel="alternate" type="text/html" href="<txp:permlink />" /> <summary type="html"><![CDATA[<txp:excerpt /><txp:body />]]</summary> <txp:if_article_image> <txp:images> <media:thumbnail url="<txp:image_url />" height="<txp:image_info type="h" />" width="<txp:image_info type="w" />" /> </txp:images> </txp:if_article_image> <txp:if_article_category> <content type="html"><![CDATA[ <p>Filed under: <txp:category_list categories='<txp:category1 />,<txp:category2 />' children="0" break=", " trim> <txp:category title link /> </txp:category_list> </p> ]]</content> </txp:if_article_category> </txp:article_custom> </feed>
There’s way more you can do. Anything that’s in the spec, is fair game. I don’t know much about that area so the above is largely guesswork.
For example, I’m not entirely sure how you generate the
<id> entries for the feed and for the articles. I suppose you could use a jot of PHP to output some
md5() string based on the article title or something. We use the blog_uid as part of the official feed, but that’s only available in prefs.
Anyway, once you have that designed how you want, you can visit
example.org?f=article-feed and it’ll spit your feed out.
There are things that need to be done or could be done, like naming it nicely (it’ll get a random name if you use the above code). And maybe using an .htaccess rule to map
?f=article-feed to make things look prettier. But on the whole you can pretty much have complete control over what your feed looks like.
All you then need to do is tell Txp the endpoint of your feed in the
<head> section and it can be discovered.
I’m sure Oleg will be able to offer way more advice on this as there may be a simpler route, but I think the above gives you ultimate flexibility in crafting feeds how you like.
EDIT: A few other threads for inspiration:
Last edited by Bloke (2020-07-13 19:18:38)