masthead image

Technology Blog

Social Bookmarks

Wednesday November 12 2008, 07:59 PM

Do you want to drive more traffic to your Drupal website? This is a Drupal PHP snippet that will generate social bookmarking links for your blog nodes. It builds a list of social bookmarks for the current blog node. Use this as part of your custom Drupal theme by inserting this into node-blog.tpl.php file.

Usage

Here is an example of how to use this Drupal snippet:

echo "<div class='bookmarks'>Bookmark:&nbsp;" . ShowBookmarks($node_url, $title, $directory) . "</div>";

Code Snippet

Here is the social bookmarking code snippet:

function BuildDeliciousLink($node_url, $title, $directory) {
  $urlLink = urlencode("http://del.icio.us/post?url=http://www.yoursite.com{$node_url}&amp;title={$title}");
  $link = "<a href='{$urlLink}' title='Delicious this'><img src='/" . $directory . "/images/badges/delicious.png' alt='Delicious logo'/>Del.icio.us</a>";
  return($link);
}
function BuildDiggLink($node_url, $title, $directory) {
  $urlLink = urlencode("http://digg.com/submit?phase=2&amp;url=http://www.yoursite.com{$node_url}&amp;title={$title}");
  $link = "<a href='{$urlLink}' title='Digg this'><img src='/" . $directory . "/images/badges/digg.png' alt='Digg logo'/>Digg</a>";
  return($link);
}
function BuildTechnoratiLink($node_url, $title, $directory) {
  $urlLink = urlencode("http://technorati.com/cosmos/search.html?url=http://www.yoursite.com{$node_url}&amp;title={$title}");
  $link = "<a href='{$urlLink}' title='Technorati this'><img src='/" . $directory. "/images/badges/technorati.png' alt='Technorati logo'/>Technorati</a>";
  return($link);
}
function ShowBookmarks($node_url, $title, $directory) {
  $linkDelicious = BuildDeliciousLink($node_url, $title, $directory);
  $linkDigg = BuildDiggLink($node_url, $title, $directory);
  $linkTechnorati = BuildTechnoratiLink($node_url, $title, $directory);
  $strOut =<<<EOD
<ul>
  <li class="first bookmark">{$linkDelicious}</li>
  <li class="bookmark">{$linkDigg}</li>
  <li class="last bookmark">{$linkTechnorati}</li>
</ul>
EOD;
  return($strOut);
}

Social Bookmarking Badges

Here are the social bookmarking badges. Please do NOT reference the images off this site. Simply right click and save the social bookmarking images to your server and reference them from there.

del.icio.us - Delicious logo
Digg - Digg logo
Technorati - Technorati logo