Following my post about Adding the Facebook Like button to your Drupal site, I figured I could post about adding a Twitter button to your Drupal site.
As with my previous post about the Facebook Like button, my approach embeds the code within node-{content type}.tpl.php.
Here's my approach...
Code:
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-url="<?php $curr_url = check_plain("http://" .$_SERVER['HTTP_HOST'] .$node_url); echo $curr_url; ?>" data-text="<?php echo $title ." | JerryJr.com"; ?>" data-via="jerryjr">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
- Find and open the node.tpl.php file in your theme folder. If you want to add the like button to each and every node, then edit this file. If you want to add it to certain content types, then you can open that specific node.tpl.php file or simply copy this file and rename to node-{insertContentTypeHere}.tpl.php (for a content type of Video, your file will be named node-video.tpl.php. If that was confusing to you, leave a comment and I'll try to explain further.
- We will want to insert the code above between <div class="content"> and <?php print $content ?>
- Change the data-via value to your own twitter username.
- Change the | JerryJr.com value to your own domain name.
- Save and upload your modified file to your server.
You can test it out on using the TWEET button on the top right of this post. Go ahead, give it a shot!
Updated on 10/06/2010
2 Comments
It occurs to me that the code
Submitted by Peet (not verified) on
It occurs to me that the code you seem to be using is slightly different from the one in your blog and actually shows the nice tweet button rather than only the link. How did you define this in your CSS?
Thanks for the informational blog post anyway!
Take a look at this updated
Submitted by Jerry on
Take a look at this updated post that I made...
Adding Twitter and Facebook Like buttons to your Drupal site