Inserting AddThis.com widget in Simple Machines Forum
After finding the AddThis.com bookmarking widget and installing the WordPress plugin here I decided I needed to add the widget to my photography forum.
What I wanted to make sure would happen is that if a visitor bookmarks a page they bookmark the first page in the thread instead of bookmarking a later page in a multipage thread. So with a little regex I built the correct URI regardless of what page the visitor is on.
And a quick note… I’m using the SEO4SMF modification so the URIs look like static pages. I’m sure something similar can be done with the normal URIs that SMF produces, but that’s a topic for a future post.
If you look at the URI that SEO4SMF produces it looks like thread_title-t123.0.html. The 0 towards the end will change depending on what page of a multipage thread you’re on. And there can be junk after the .html depending on whether you’re jumping to read posts or not which had to be dumped. So what I wanted to do was replace the number at the end with 0 followed by .html and nothing else. It was a pretty easy regex replacement.
-
// AddThis.com Button
-
$urlAddThis = ‘http://’.$_SERVER[‘SERVER_NAME’].$_SERVER[‘REQUEST_URI’];
-
$urlAddThis = preg_replace(‘/\.([0-9]*)\.html(.*)$/’, ‘.0.html’, $urlAddThis);
-
echo ‘<div style="float:right;">’;
-
echo ‘
-
<!– AddThis Bookmark Button BEGIN –>
-
<script type="text/javascript">
-
addthis_url = "’.$urlAddThis.‘";
-
addthis_title = document.title;
-
addthis_pub = "YourUserName";
-
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12"></script>
-
<!– AddThis Bookmark Button END –>
-
‘;
-
echo “\n</div>\n“;
-
// EOF AddThis.com
Put the code into the Display.template.php file in whatever theme you’re using. For my site I put it just above the code that displays the link tree (look for theme_linktree()) and floated it to the right so it’s about the same level.
You’re going to need to change line 10 to use your AddThis username instead of the dummy value that’s in the code.
Question, Comments...
Do you have more questions. Please either leave a comment below or join us in our new forum.

