I want to use the new www.AddThis.com service, but it says "Simply copy-and-paste the code into your pages, between the and the tags. If your website uses templates, you can also copy the code into your template, so the button will appear on all your pages automatically."

Does this make sense? Where exactly would I paste in this code in Drupal using the BlueMarine theme?

Thanks for your time and help, it is greatly appreciated.

Comments

nevets’s picture

You could add the code directly to the page.tpl.php file where you want the button to show. You could also create a custom block and use the code for the button as the body of the block, just make sure you select the correct input filter (either Full HTML or possibly PHP code if the snippet includes javascript)

domcat’s picture

For social bookmark, the Add to Any widget is far better. It contains just about every sharing and saving service in a searchable menu, and it's a bit easier on the (old) eyes. Here's the code to get Add to Any to work on Drupal:

<?php if ($links): ?>
  <div class="links">
    <?php print $links; ?>

    <?php if ($page): ?>

      <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?linkname=&amp;linkurl="><img src="http://www.addtoany.com/bookmark.gif" width="91" height="16" border="0" title="Bookmark" alt="Bookmark"/></a>

      <script type="text/javascript">
      a2a_linkname=document.title;
      a2a_linkurl=location.href;
      </script>
      <script type="text/javascript" src="http://www.addtoany.com/js.dropdown.js?type=page"></script>

    <?php endif; ?>

  </div><br />
<?php endif; ?>

It might be better to replace document.title and location.href with the actual page's title and permalink, but I'm not sure how to do that. Anyone?

natts’s picture

Just use this module instead - much easier: http://drupal.org/project/addtoany

hammoco’s picture

Register at www.addthis.com. Copy the code, goto admin/build/block/add, name the block addthis paste the code and select the input format as PHP code. Bingo, jobs a good un!

US421’s picture

You could create a block, or put it in your footer but a block seems like what you want. Make sure to enable full HTML if it uses javascript, and that sort of thing usually does. You could also paste it directly into your template depending on where you want it to show up, but this seems easier to manage.

Don't know what tags you mentioned, but I assume it was <body>and</body>.

coolasclyde’s picture

I created a new block and it seems to work fine. Thank you!

chris.coppola@rsmart.com’s picture

I'm looking to do the same thing but I'd like it to display under each post (inline) like the Service Links do. Is that what you did? It doesn't seem like you can get it to display that way as a block.

bobdalob’s picture

I can confirm that Add This works when placing the code in a block and selecting php as input type. The new drop-down widget, which is currently in beta, does not work in a block.

I do think it is better placed in the links section for the node. Anyone?

VenDG’s picture

I added a div tag after the print contents in node.tpl.php like so:

  <div class="content">
    <?php print $content ?>
  </div>

<div>
<!-- AddThis Bookmark Button BEGIN -->
... the addthis code ...
<!-- AddThis Bookmark Button END -->
</div>

The dropdown widget works in the div.

Programming: Onaje.com, Photography & Art: Jaelin.com

Asapcorp’s picture

thanks this helped me to addthis widget in my drupal site

http://codeitbetter.com

druvision’s picture

A good place for the AddThis widget seems to be below each post, in the same line of the 'add new comment' link, like in this drupal site. But which phptemplate file do I have to change in order to get the effect? I would be very greatfull if somebody can post examples of changing the links line below the post.

Thanks

Amnon
-
Professional: Drupal Israel | Drupal Development & Consulting | בניית אתרים
Personal: Hitech Dolphin: Regain Simple Joy :)

Amnon
-
Amnon Levav - Drupal Development Management Consultant
Druvision - Web Solution Experts

silverwing’s picture

it should go in node.tpl.php

~silverwing
___________________________
MisguidedThoughts | tvTonight

druvision’s picture

It's really much simpler then I thought - In the past I tried to change something like links.tpl.php - but node.tpl.php is indeed much easier.

AddThis is now integrated into the Drupal Israel website.

Tip: only put the addThis gadget on the full pages. Putting it on a teaser view causes AddThis to mistakenly add the URL of the teaser, instead of the URL of the page.

Sample code:

<?php if ($links): ?>
  <div class="links">
    <?php print $links; ?>

    <?php if ($page): ?>

      <!-- AddThis Bookmark Button BEGIN -->
      <script type="text/javascript">
        addthis_url    = location.href;
        addthis_title  = document.title;
        addthis_pub    = 'write-your-addthis-user-name-here';
      </script>
      <script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
      <!-- AddThis Bookmark Button END -->

    <?php endif; ?>

  </div><br />
<?php endif; ?>

Amnon
-
Amnon Levav - Drupal Development Management Consultant
Druvision - Web Solution Experts

Battlehard’s picture

Hi I'm totally new to Drupal (like i just set a site up a couple of hours ago) and i got this working with Levavie's snippet above in less then 2 mins. I also got it to work as a block by just pasting the code in and removing the comments then i set it to full html and it worked fine for me. but putting it in the node.tpl.php worked better.

Im Well happy and had to tell someone!

krancour’s picture

It seems to me that all the solutions that revolve around adding the AddThis widget using theme functions or templates may be easy but are not entirely ideal. I say this because I can hardly imagine site administrators wanting their AddThis widget to evaporate when they switch themes. The widget is something that that should be part of the node itself.

Where I am going with this is that I am currently working on an AddThis module for adding the bookmarking widget to nodes and the feed widget as a block. This is my first module, so I'm taking my time to make sure I get it right, but I'm sure others will find value in this. I'm happy to contribute it to the community if anyone can walk me through the process for that. If not, I'm sure my Drupal book I've been reading covers it.

At any rate, anyone who's been wishing a module for AddThis would be available at some point, hang in there! I'm working on it.

VenDG’s picture

This is a good point but site admins should be keeping track of site modifications anyway. In my case, I am using a custom theme so there are already theme specific changes so adding this code to my tpl file is not a big deal. For someone not doing too much customization and using the regular themes, or wanting to cut down on the amount of custom code added to their themes, a module would fit the bill nicely.

Programming: Onaje.com, Photography & Art: Jaelin.com

druvision’s picture

Sounds great. Encouraging you to continue.

Will be really usefull to have blocks for the different AddThis widgets with no need for theme changes. Custom regions may always be supplied in theme, but that's all.

If the addthis can be planted automatically in non-block pages - like in the beginning of a node - it will be even better. See the adsense_injector module for an example.

Amnon
-
Professional: Drupal Israel | Drupal Development & Consulting
Personal: Hitech Dolphin: Regain Simple Joy :)

Amnon
-
Amnon Levav - Drupal Development Management Consultant
Druvision - Web Solution Experts