The folks at DZone provide a great way for developers to share links in one, concentrated area. URLs which rank highly in their system (those that receive many “up” votes) often get quite a bit of traffic. As a result, many developers use the DZone button to provide their visitors a way to rate articles directly from their own website.
Image may be NSFW.
Clik here to view.
Do you use the DZone button on your website? If not, you should definitely consider it. Unfortunately, each one of these buttons requires the inclusion of a JavaScript file, which adds an HTTP request (and thus slows down the page). With some quick studying of the included JavaScript, it’s possible (not to mention quite easy) to generate this same button with only PHP, thus saving a request.
Here’s the function to do so:
function dzone_button( $style, $url, $title, $description = false )
{
$html = '<iframe src="http://widgets.dzone.com/links/widgets/zoneit.html?t=' . $style;
$html .= '&url=' . urlencode( $url ) . '&title=' . urlencode( $title );
if( $description !== false )
$html .= '&description=' . $description;
if( $style == 1 )
$html .= '" height="70" width="50" scrolling="no" frameborder="0"></iframe>';
else
$html .= '" height="25" width="155" scrolling="no" frameborder="0"></iframe>';
return $html;
}
It requires the same parameters are the JavaScript file: the type of button (1 for tall, 2 for wide), URL, title, and description (optional).
To use it, just plug, chug, and echo:
echo dzone_button( 1, 'http://example.com', 'Example', 'Example description' );
If you’re using WordPress, consider the following snippet:
echo dzone_button( 1, get_permalink(), get_the_title() );
If you want a description, use get_the_excerpt
:
echo dzone_button( 1, get_permalink(), get_the_title(), get_the_excerpt() );
That’s all there is to it; you’ve generated the same button without the JavaScript. The only real difference is that you’ll have an iframe
directly in the HTML page rather than one generated by JavaScript. Happy DZoning!