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 {
// 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.
Comments
RSS Comments Feed
SvenPhilippe
"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
Matt
Matt
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.
jesth
case 'twit':
start = '<!-- NOBADGE';
end = '-->\n';
break;
i'm sure it could be done better, but hey, it works, yay for lazyness :)
Matt
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.
jesth
<!-- NOBADGE -->
better code:
case 'twit':
start = '<!-- NOBADGE -->';
end = '';
break;
jesth
<!-- NOBADGE-->
just to clearify, for others who might be in doubt.
Matt
Thanks for the note.
jesth
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?
Matt
Just change the if condition, instead of looking for NOBADGE
if (strpos($text,'<!-- NOBADGE -->') === false)
change it to;
if (_ADMIN)
jesth