Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-06-02 17:48:42

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 165
Website

kuo_json_feed: offer a JSON Feed of articles

This plugin creates JSON Feed Version 1 of Textpattern’s articles that have Live status. If you want to get recent articles from all sections, then feed URL looks like:

yoursite.com?kuo_json_feed

Using plugin’s version 0.2 JSON Feed can be limited to a certain section (that section is “blog” in this example):

yoursite.com?kuo_json_feed=blog

Here’s a link element that can be put inside <head></head> block:

<link rel="alternate" type="application/json" title="JSON feed" href="<txp:site_url />?kuo_json_feed=blog">

Limit articles

In Textpattern: Admin -> Preferences -> Feeds -> How many articles should be included in feeds?

Limit sections

In Textpattern: Presentation -> Sections -> (click a section) -> Syndicate articles? -> Yes/No

Clean URL’s

Nicer URL’s for feeds can be offered by updating the .htaccess file in website’s root. Update it for example with these two lines:

RewriteRule ^feed.json$ ./index.php?kuo_json_feed
RewriteRule ^([\-a-zA-Z0-9]+)-feed.json$ ./index.php?kuo_json_feed=$1

…they allow feeds to be opened from yoursite.com/feed.json and yoursite.com/blog-feed.json (the “blog” part is again an example).

Last edited by kuopassa (2017-06-16 13:37:30)

Offline

#2 2017-06-02 18:05:45

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,238
Website

Re: kuo_json_feed: offer a JSON Feed of articles

Wonderful, thanks so much Petri


Yiannis
——————————
neme.org | hblack.net | LABS | NeMe @ github

Offline

#3 2017-06-02 19:22:46

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 165
Website

Re: kuo_json_feed: offer a JSON Feed of articles

Thanks for the nice feedback, colak. :-)

Offline

#4 2017-06-12 11:47:39

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 2,815
Website

Re: kuo_json_feed: offer a JSON Feed of articles

Thanks. I can’t seem to get the .htaccess rule to work, can anyone verify?…

RewriteRule ^feed.json$ ./index.php?kuo_json_feed

Offline

#5 2017-06-12 13:14:52

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,238
Website

Re: kuo_json_feed: offer a JSON Feed of articles

Hi phil, I can confirm that the rewrite rule does not work on my server either.


Yiannis
——————————
neme.org | hblack.net | LABS | NeMe @ github

Offline

#6 2017-06-13 00:19:49

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 165
Website

Re: kuo_json_feed: offer a JSON Feed of articles

Did you put them at the very end of .htaccess file? That could explain why it’s not working. :-) Here’s a screenshot of my .htaccess file. Stuff related to JSON URL’s should work if they’re before those conditional rules like RewriteCond %{REQUEST_FILENAME} -f [OR].

Offline

#7 2017-06-13 00:58:16

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 1,184
Website

Re: kuo_json_feed: offer a JSON Feed of articles

kuopassa wrote #305945:

Did you put them at the very end of .htaccess file? That could explain why it’s not working. :-) Here’s a screenshot of my .htaccess file. Stuff related to JSON URL’s should work if they’re before those conditional rules like RewriteCond %{REQUEST_FILENAME} -f [OR].

Yes, that way it works fine – I had originally put it at the end of the <IfModule mod_rewrite.c> rewrite block in my .htaccess file, and that failed.

~~~~

Another issue: with the pref “Feeds > Syndicate article excerpt only?” :

(given a site with 5 articles, 3 of which have an excerpt)
If the pref is set to Yes, then the JSON feed contains all articles. However, change the pref to No, the feed only contains 3 articles (those that actually have an excerpt@. That is strange, I would expect the opposite.

For comparison, the Atom feed, with the pref set to No has both <content type="html" /> and a <summary type="html" /> when the article has both body and excerpt. With the pref set to Yes, there is only a <summary type="html" />, which contains either the body (if no excerpt is available) or the excerpt.

Offline

#8 2017-06-13 05:11:31

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,238
Website

Re: kuo_json_feed: offer a JSON Feed of articles

kuopassa wrote #305945:

Did you put them at the very end of .htaccess file? That could explain why it’s not working. :-) Here’s a screenshot of my .htaccess file. Stuff related to JSON URL’s should work if they’re before those conditional rules like RewriteCond %{REQUEST_FILENAME} -f [OR].

That did it! thanks so much.


Yiannis
——————————
neme.org | hblack.net | LABS | NeMe @ github

Offline

#9 2017-06-15 15:06:28

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,238
Website

Re: kuo_json_feed: offer a JSON Feed of articles

I found another small issue. Even when using the clean url, the json feed still lists its ?kuo_json_feed alternative. I can understand why but is there a way to change that?

>Edit. I Just saw the line in the code… Done:)

Last edited by colak (2017-06-15 15:11:32)


Yiannis
——————————
neme.org | hblack.net | LABS | NeMe @ github

Offline

#10 2017-06-16 13:41:07

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 165
Website

Re: kuo_json_feed: offer a JSON Feed of articles

phiw13 wrote #305946:

Another issue: with the pref “Feeds > Syndicate article excerpt only?

I’ll take a look at soon that and try to fix it. My “coding mood” is not a constant, so when a few days ago I had a clear understanding how to make “code” happen, now that’s gone and I’d like to do photographing or something else instead. :-]

Offline

Board footer

Powered by FluxBB