Add a retweet button to your sNews CMS articles and pages

Add a retweet button to your sNews CMS articles and pages

Notice those little twitter "retweet" badges popping up all over? Pssst... look to the right for an example. Face it, Twitter is here to stay and can be a useful tool if used correctly.

I wanted to add this to all my posts, but I didn't have any desire to edit every article and insert them, so I've written a dead simple little hack to add a badge on the articles and pages of my sNews CMS installation. You can read more about the badge and service at Tweetmeme.

All you need to do is open your snews.php file, look for;

} else {
    $shorten = 9999000;

and then stick the tweetmeme button code within, as below. Make sure to change the url shortener if you like, and put your twitter username in as the RT source;

} else {
    if (strpos($text,'<!-- NOBADGE -->') === false) {
    $tweet = '<span class="retweet"><script type="text/javascript">
        tweetmeme_service = \'\';  // the url shortener
        tweetmeme_source = \'twittername\'; // the @username who is tweeted
        tweetmeme_style = \'\'; // use compact for small badge
        <script type="text/javascript" src=""></script></span>';
        $text = $tweet.$text;
    $shorten = 9999000;

Now add the style to your stylesheet;

.retweet {
  float: left;
  margin: 10px 10px 0 0;

What if I don't want the badge on an article or page? Simple, just insert the HTML comment <!-- NOBADGE --> anywhere within the article or page text, and voilá , no more badge.

Tip... this code can also be used to insert digg,, and any other kind of badge you like.



You might like


"Before using the Add a retweet button's Mod my wife was angry at me. My dog couln't stop barking. I was losing my hair. I was allways short of money.
Now my pockets are full of &euro;. My wife is happy and my dog was shot by a neighbor and I wear a wig.
Thanks to that tremendous Mod."
And it works with the 1.6 sNews version too: Go to and make my day.

Hahaha! Awesome :)

Unfortunately it seems to me that the tweetmeme API is insanely slow, it seems to be causing my pages to load ridiculously slow.

I noticed a huge spike in load times on the Google Webmaster Tools Performance overview page on the exact day I started using it.

I just removed it from all pages but this one (and reworked some other bits of my site). I will see if there is a corresponding drop in GWT loading times over the next couple of weeks.

I just tested this, and must say, well done, and for the NOBADGE insertion, I created this rather lazy button:

case 'twit':
start = '<!-- NOBADGE';
end = '-->\n';

i'm sure it could be done better, but hey, it works, yay for lazyness :)

Nice idea jesth.

For anyone wondering what he's talking about, if you open admin.js, inside the function tag(tag), and add the code he noted

Then inside snews.php, in the function buttons(), find the line with
$insert = array('img', 'link'... then add "twit" to the list.

Tada, now you have a clickable button.

Small error in my "code" a missing space made the NOBADGE still appear after adding it via my link, error being the missing space after NOBADGE here:
<!-- NOBADGE -->

better code:

case 'twit':
start = '<!-- NOBADGE -->';
end = '';

Sorry for doubleposting but the error code was
<!-- NOBADGE-->

just to clearify, for others who might be in doubt.

No worries jesth, yeah, I was a little lazy and used strpos for this little hack instead of a regex or stripos even, so yeah, the badge part has to be exact, including the spaces and CAPS.

Thanks for the note.

Hi (again)

Was wondering, is it possible to make it "Admin view only" say you add this great mod, but only want it visible to admin when he is logged in, instead of adding the <!-- NOBADGE--> to every single article, or is there an even better way of doing so?


Just change the if condition, instead of looking for NOBADGE

if (strpos($text,'<!-- NOBADGE -->') === false)
change it to;
if (_ADMIN)

Ohh.. why didn't I think of that, thanks alot.

Comments are closed. No new comments allowed.

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