Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-07-13 18:05:37

From: Lancashire
Registered: 2004-04-19
Posts: 1,470

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 excerpt and body?

BB6 Band My band
Gud One My blog


#2 2020-07-13 18:44:32

From: Leeds, UK
Registered: 2006-01-29
Posts: 11,286
Website GitHub

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

  1. Visit Prefs->Admin panel
  2. Ensure Advanced options is on
  3. Visit the ‘Advanced options’ area in prefs
  4. In the Custom form template types add a new type to output feeds:

Save the changes.

Step 2: Craft your feed

  1. Visit Presentation>Forms
  2. Create a new Form
  3. Select its type as Feed
  4. Give it a name such as article-feed
  5. 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>

<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>

<media:thumbnail url="<txp:image_url />"
   height="<txp:image_info type="h" />" width="<txp:image_info type="w" />" />
<content type="html"><![CDATA[
   <p>Filed under:
    <txp:category_list categories='<txp:category1 />,<txp:category2 />' children="0" break=", " trim>
        <txp:category title link />


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 /feed to ?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)

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp


#3 2020-07-13 19:50:33

From: Lancashire
Registered: 2004-04-19
Posts: 1,470

Re: Add image to feeds

Thanks, Stef, I didn’t know about that at all or those other threads. Plenty to get to grips with!

BB6 Band My band
Gud One My blog


Board footer

Powered by FluxBB