Add a retweet button to your sNews CMS articles and pages
filed under: sNews CMS / Hacks & Mods
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 {
// BEGIN NEW CODE
if (strpos($text,'<!-- NOBADGE -->') === false) {
$tweet = '<span class="retweet"><script type="text/javascript">
tweetmeme_service = \'bit.ly\'; // the url shortener
tweetmeme_source = \'twittername\'; // the @username who is tweeted
tweetmeme_style = \'\'; // use compact for small badge
</script>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></span>';
$text = $tweet.$text;
}
// END NEW CODE
$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, delicious.com, and any other kind of badge you like.
8 comments
Add a new comment »Categories
Recent Entries
Recent Comments
- Matt (Hi jesth, everything is controlled through the CSS styling ...)
- jesth (I really like this mod, I just have one thing, how the ...)
- Matt (No worries jesth, yeah, I was a little lazy and used strpos ...)
- jesth (Sorry for doubleposting but the error code was <!-- ...)
- jesth (Small error in my "code" a missing space made ...)
- Matt (Wow, that is quite the mod to be honest. I agree that if ...)
- Simon (Thanks for the feedback Matt. I believe t would just be ...)
Popular Entries
- Light-weight related articles mod for sNews 1.7 (5/5)
- Gravatar mod for sNews 1.7 (5/5)
- Compact archives for sNews 1.7 (5/5)
- Command & Conquer Generals, and the Zero Hour expansion on the Acer Aspire One netbook (4.75/5)
- Jagged Alliance 2 runs perfect on the Aspire One (4.75/5)
- An improved tag cloud for sNews 1.7 (4.67/5)
- Image / math hybrid captcha version 2, vastly improved (4.64/5)
Jan 14th, 2010 at 5:29 am
Testimonial:
"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 €. 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 http://www.hiseo.fr/optimisations/referencement_naturel-augmenter_trafic-site_web/ and make my day.
:D
Jan 14th, 2010 at 5:39 am
Hahaha! Awesome :)
Jan 25th, 2010 at 5:27 pm
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.
Mar 5th, 2010 at 1:13 am
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';
break;
i'm sure it could be done better, but hey, it works, yay for lazyness :)
Mar 5th, 2010 at 9:53 am
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.
Mar 7th, 2010 at 8:02 am
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 = '';
break;
Mar 7th, 2010 at 8:05 am
Sorry for doubleposting but the error code was
<!-- NOBADGE-->
just to clearify, for others who might be in doubt.
Mar 7th, 2010 at 10:14 pm
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.