Professional Website Design Company UK
Support us Advertise Write for PM Design Submit Freebie Submit Your Website

How to implement TweetMeme Button on your website

3
 
Posted on 14th Nov, 2009. Posted in: , ,

re-tweet button implementationIn this very short article I am going to show you how to implement a TweetMeme badge to your website. This is a great way to encourage your visitors to re-tweet your story. You might want to implement it to your WordPress or non WordPress website. I’ll show both ways of getting a TweetMeme badge.

What is TweetMeme?

 

TweetMeme is a service that puts all the popular links on Twitter together in one place to determine which links are popular. Then it takes these links and categorises them in order to filter out what you are interested in. You can find out more on TweetMeme.

TweetMeme Button on your post or page

 

The button provides a URL and the title of the story or page. Every single link that is posted on Twitter adds one to the tweet count of the story. So this TweetMeme button (badge) can be a very good idea to remind to your visitors to re-tweet your story. TweetMeme website describes an implementation processes but they did´t work for me, so I decided to write about custom implementation. So, let´s crack on!

TweetMeme badge php function

 

You will need to include this php function at the end of your functions.php file. If you are not using a WordPress and don’t have a functions.php file, just simply paste it as a php code on a page before any header request.

<?php
function tweetmeme(){
?>
<div style="float: right; margin: 5px 10px 5px 0px;">
<script type="text/javascript">
tweetmeme_url = ‘<?php the_permalink(); ?>’;
</script>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>
</div>
<?php
}
?>

If you are not using WordPress, you need to get the current page url and replace with it. Read my post on How to get the current page url.

If you want to add your twitter id to visitors re-tweet, next to the url, you need to add one more line just after the tweetmeme_url in our code.

tweetmeme_source = ‘pmdesignweb’; /*this is your twitter name */

Getting badge displayed on your page

 

Now you have got a few choices depending on what you want to do. You might want to show the badges on every single post, if this is the case just locate your posts template (index.php or single.php for WordPress) and echo the function just before the or . If your website is non WordPress just echo this function where you want your badge to be displayed.

<?php echo tweetmeme(); ?>

If you want to display in on some of the posts only and you would like to have a full control on what post the badge is displayed you might want to you custom fields on WordPress. If this is the case, instead of echoing the function we can check if the custom field was defined and if it was then echo the function. See the code below:

<?php
$check_sm = get_post_meta($post->ID, ‘tweetmeme’, $single = true);
if($check_sm != ”)
tweetmeme();
?>

Now create a custom field on the post called TweetMeme and set the value to true. The badge will only be displayed on posts containing this custom field. Enjoy!

Enjoyed this entry? Share it around!

 

Share it with others. Make others aware about web design tips, techniques and news.

 
 

You may also like to read

 
 
 
  • LeviD

    Very nice toturial its realy important!

  • http://www.sebastiansulinski.co.uk Seb

    Great article – keep up the good work!

  • Bob

    Really useful information! and it works!!!

  •  
  •  
     
     
     
    Copyright © 2008 - 2012. All rights reserved.
    Pawel Martuszewski Design – Web Design Tutorials, operated by Direct Media Design