HTML-Advisor
Mostly practical advices

How to add social bookmarking scripts like “Digg this”?

Social bookmarking websites such as Digg and del.icio.us are great tools to drive traffic to your site and to provide important links (Read more About Social Bookmarks). These services allow varying degrees of automated submissions, and so here you will find the required code to add to your pages to facilitate submission.

Digg bookmark code

Digg does not allow complete automated submission, requiring some human interaction. There are two versions of the code: PHP and Javascript.

PHP Digg script

Using PHP, you can create the “Digg this” link on the server before sending the page to the browser. The code is (all one line):

<a href="http://digg.com/submit?phase=2&url=<?php echo urlencode("http://www.html-advisor.com" . $_SERVER["REQUEST_URI"]); ?>”>Digg this</a>
This produces the following link: Digg this.

Javascript “Digg this”

You can use it as a bookmarklet: just drag the link to your bookmark toolbar. A simplified version of the code is:

<a href="javascript:location.href='http://digg.com/submit?phase=2&url=' + encodeURIComponent(document.location.href) + ' '">Digg this</a>
This produces this link: Digg this.

del.icio.us submission code

del.icio.us is a very popular social bookmarking service. Its link submission system is similar to Digg’s. Again, we have PHP and Javscript codes.

del.icio.us PHP submission code

The PHP code to submit to del.icio.us is:
<a href="http://del.icio.us/post?v=2&url=<?php echo urlencode("http://www.html-advisor.com" . $_SERVER["REQUEST_URI"]); ?>&title=<?php echo urlencode($PAGE_TITLE);?>” title=”Post to del.icio.us”>Post page to del.icio.us</a>
This produces this link: Post page to del.icio.us

Note the $PAGE_TITLE variable. This needs to be changed to the page’s actual title. If you are using blog software or a content management system (CMS), you might find that this variable is already present, but called something else. If not, you can submit the page without a title, but this forces the user to type it in. In this case, the code will be:
<a href="http://del.icio.us/post?v=2&url=<?php echo urlencode("http://www.html-advisor.com" . $_SERVER["REQUEST_URI"]); ?>” title=”Post to del.icio.us”>Post page to del.icio.us</a>
Which produces this link: Post page to del.icio.us. Notice the difference?

del.icio.us Javascript submission code

The Javascript code is more straightforward:
<a href="javascript:location.href='http://del.icio.us/post?v=2&url=' +encodeURIComponent(document.location.href)+'&title=' +encodeURIComponent(document.title)+' '">Post to del.icio.us</a>
Output: Post to del.icio.us.

Furl posting code

The Furl submission code is similar to the del.icio.us code above.

Furl PHP code

The code:
<a href="http://www.furl.net/storeIt.jsp?t=<?php echo urlencode($PAGE_TITLE);?>&u=<?php echo urlencode("www.html-advisor.com" . $_SERVER["REQUEST_URI"]); ?>”>Post page to Furl</a>
Which produces: Post page to Furl

Again, notice the $PAGE_TITLE variable. Unlike using the del.icio.us, if you do not provide a link title, Furl automatically sets it to ‘untitled’. You may want to avoid that.

Furl Javascript code

The code:
<a href="javascript:location.href='http://www.furl.net/storeIt.jsp?u='+encodeURIComponent(document.location.href)+'&t='+encodeURIComponent(document.title)+' '">Post to Furl</a>
Which produces: Post to Furl.

Source: http://ekstreme.com

Tags: , , , , ,

Related:

Posted in JavaScript, PHP. 1,955 views
Responses are currently closed, but you can trackback from your own site.

No Comments

Sorry, the comment form is closed at this time.