Add individual RSS feeds for articles in sNews 1.7
filed under: sNews CMS / Hacks & Mods
Today I was tinkering around with sNews and snooping through my EN.php language file, and to my surprise I noticed an unused language variable.
It appears as though at some point that was a plan to add RSS feeds for individual articles. This is a great idea in my opinion, so I decided tyo try and make it happen, without requiring too much hacking. This is the unused variable in EN.php here;
$l['rss_comments_article'] = 'RSS Comments for this article';
I was thinking about enabling this feature quite some time ago, and obviously someone else had the idea to add individual RSS feeds for each article before I did, so I figured it was time to code it in and make it available. I think this feature would be a great value to people wanting to track an article's comments to see if there has been a reply to a question or to just stay updated on bugs &/or changes.
I have made this as dead simple of a mod as I can, so backup your snews.php and work on a copy.
STEP 1) find function rss_contents, and add the following highlighted code, there are 2 small pieces, add them both;
header('Content-type: text/xml; charset='.s('charset').'');
$limit = s('rss_limit');
$url = cleanXSS($_SERVER['REQUEST_URI']);
$start = strpos($url,'?')+1;
$aid = substr($url,$start);
$aid = str_replace("/", '',$aid);
if (ctype_digit($aid)) {
$extra_sql = "articleid = '".$aid."' AND ";
}
switch($rss_item) {
case 'rss-articles':
$heading = l('articles');
$query = _PRE.'articles'.' WHERE position = 1 AND visible = \'YES\' AND published = 1 ORDER BY date';
break;
case 'rss-pages':
$heading = l('pages');
$query = _PRE.'articles'.' WHERE position = 3 AND visible = \'YES\' AND published = 1 ORDER BY date';
break;
case 'rss-comments':
$heading = l('comments');
$query = _PRE.'comments'." WHERE ".$extra_sql." approved = 'True' ORDER BY id";
break;
}
STEP 2) Now find the comment form in the function comment, and add the following highlighted code;
$art_value = empty($articleSEF) ? $subcatSEF : $articleSEF;
echo '<div class="commentsrss"><a href="'._SITE.'rss-comments?'.$_ID.'">'.l('rss_comments_article').'</a></div>'."\r\n";
echo '<br /><div class="commentsbox"><h2>'.l('addcomment').'</h2>'."\r\n";
STEP 3) Now style the commentsrss class however you like, this is basically what I use, feel free to copy;
.commentsrss {
clear: both;
padding: 4px 36px 0 0;
margin-bottom: 4px;
height: 32px;
color: #000;
vertical-align: middle;
text-align: right;
}
.commentsrss a {
font-variant: small-caps;
font-size: 1.2em;
color: #000;
text-decoration: none;
}
That's it, upload snews.php and you should have a link above each comment form that will allow your users to subscribe to the individual articles.
An example? Just look down, I'm using it on my own site here.
13 comments
Add a new comment »Categories
Recent Entries
Recent Comments
- Dede (I checked it today in a shop. GT2 had some troubles with six ...)
- Matt (Bintang, You need to re-direct the url, try ...)
- jesth (Ohh.. why didn't I think of that, thanks alot.)
- Matt (Dede, I don't have Gran Turismo 2, any of the 2nd+ generation ...)
- Matt (Jesth, Just change the if condition, instead of looking for ...)
- jesth (Hi (again) Was wondering, is it possible to make it ...)
- Bintang Sembilan (Matt, thanks for your modd. I have apply it to my ...)
- Dede (Hello there. Can you check something for me? I want to buy ...)
- Matt (I think it's a driver issue Terrence, or it was a driver issue. ...)
Popular Entries
- Light-weight related articles mod for sNews 1.7 (4.5/5)
- Image / math hybrid captcha version 2, vastly improved (4.42/5)
- 1024x600 netbook wallpapers of Evangeline Lilly (4.4/5)
- Compact archives for sNews 1.7 (4.4/5)
- sNews Ajax Polls mod now available (4.38/5)
- Pretty date and comments bars in sNews CMS (4.35/5)
- Page caching mod for sNews 1.7 (4.33/5)
- Gravatar mod for sNews 1.7 (4.29/5)
- An improved tag cloud for sNews 1.7 (4.29/5)
Nov 10th, 2009 at 12:20 pm
Adding a test comment to this article so you can see the individual article's RSS comments feed.
Nov 11th, 2009 at 1:48 am
First of, it's been awhile since i've done any modding to my site, and then I find this, really nifty mod, gonna test it latet on today, thanks alot Matt
Nov 11th, 2009 at 3:23 am
Good shot Matt! You got 1 more star.
Nov 13th, 2009 at 4:37 am
Tested it now, and it's working nicely, thanks again Matt.
Nov 22nd, 2009 at 12:27 pm
Hi Matt, Exelent work! You can specify the $articleSEF instead of numbers. For example:
<a href="'._SITE.'rss-comments?article='.$art_value.'">'.l('rss_comments_article').'</a>
IMHO, it looks more understandable to the user.
Nov 22nd, 2009 at 12:39 pm
Or for better viewing: if ($numrows > 0) echo '<div class="commentsrss"><a href="'._SITE.'rss-comments?article='.$articleSEF.'">'.l('rss_comments_article').'</a></div>'."\r\n";
Nov 23rd, 2009 at 9:02 am
Hi Different,
On your first point, that's definitely do-able, you'd need to join the category table in the first part of the switch statement, as of right now, it is pulled by the sNews retrieve function, which is quite inefficient actually.
On your second comment, you can do that, I like to keep the option always there in case someone may see an article and want to keep tabs on future comments even if there hasn't been any comments yet.
Nov 24th, 2009 at 6:39 am
Hi, Matt! You are absolutely right, but I was mistaken a bit. Here's my corrected version for compensation:
and
echo '<p class="commentsrss"><a href="'._SITE.'rss-comments?id='.$_ID.'&articleSEF='.$art_value.'" rel="nofollow">'.l('rss_comments_article').'</a></p>'."\r\n";I added a tag rel="nofollow" for search engines only. I'll be glad if someone is needed.
Nov 24th, 2009 at 7:43 am
Afraid that I was banned, but ... It works! :)
$limit = s('rss_limit'); $url = cleanXSS($_SERVER['REQUEST_URI']); $start = strpos($url,'?id=') + 4; $tail = substr($url,$start); $lenght = strpos($tail,'&articleSEF='); $aid = substr($tail,0,$lenght); if (ctype_digit($aid)) $extra_sql = "articleid = '".$aid."' AND ";Nov 24th, 2009 at 9:06 am
lol, cool different, that's good stuff, I have codified your comment code for readability. I need to add a bbcode just for formatting code some time.
Jan 25th, 2010 at 7:05 am
Now this one for categories would be just Dandy
May 9th, 2010 at 4:39 am
Hello
Thank you for this mod!, However, is there a mod for the same classes, I look for how to make a
rss individually by category
In advance thank you for your help
Yule
May 9th, 2010 at 7:35 am
Hi Yule & Patric,
I don't think their is a mod for category RSS feeds, it would probably require a much larger rewrite of the RSS function.
I may have a look at writing it some time, no promises right now though :)