Add individual RSS feeds for articles in sNews 1.7

Add individual RSS feeds for articles in sNews 1.7

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.

Tags

 

You might like

Comments


Adding a test comment to this article so you can see the individual article's RSS comments feed.


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


Good shot Matt!
You got 1 more star.


Tested it now, and it's working nicely, thanks again Matt.


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.


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


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.


Hi, Matt! You are absolutely right, but I was mistaken a bit. Here's my corrected version for compensation:

$url = cleanXSS($_SERVER['REQUEST_URI']);
$start = strpos($url,'?id=') + 4;
$end = strpos($url,'&') + 2;
$aid = substr(substr($url,$start),0,$end);
if (ctype_digit($aid)) $extra_sql = "articleid = '".$aid."' AND ";
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.


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


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.


Now this one for categories would be just Dandy


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


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

Comments are closed. No new comments allowed.

Copyleft 2002 - 2017 Matt Jones
Hand crafted with HTML5 & CSS3
↑ Back to top