4

Using Drupal 7.2 I've successfully added a Google Adsense banner to my website by creating a new block with admin/structure/block/add and puting Google's code as "raw HTML" (added that "raw HTML" format first in admin/config/content/formats/add) there:

<script type="text/javascript"><!--
google_ad_client = "XXX";
/* block1 */
google_ad_slot = "YYY";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Now I'm trying to add another block containg a Like-button by the russian social network Odnoklassniki.ru:

Like

My problem is - they want me to add:

Head:

<link href="http://stg.odnoklassniki.ru/share/odkl_share.css" rel="stylesheet">
<script src="http://stg.odnoklassniki.ru/share/odkl_share.js" type="text/javascript"></script>

<style type="text/css">
.odkl-klass, .odkl-klass:hover {background:none;}
.odkl-klass {background: url(/images/128x128.png) no-repeat;}
</style>

Body:

<a class="odkl-klass-stat" href="http://preferans.de" onclick="ODKL.Share(this); return false;"><span>0</span></a>

And call:

<body onload="ODKL.init();">

How could I do it the best way please? (it would be good not to have it updated every time I update the Drupal version)

When I just try to put all 3 pieces listed above into a block (as I did for Google banner) - the button doesn't work.

closed as primarily opinion-based by kiamlaluno May 17 '16 at 7:57

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

6

The link and the script can be added through drupal_set_html_head() head

drupal_set_html_head('<link href="http://stg.odnoklassniki.ru/share/odkl_share.css" rel="stylesheet"><script src="http://stg.odnoklassniki.ru/share/odkl_share.js" type="text/javascript" ></script>');

On clicks are not good practice in drupal. Behaviors are used in stead.

So in your block you can output

  <a class="odkl-klass-stat" href="http://preferans.de"><span>0</span></a>

You can then set a couple of behaviors in your own script, which you can put in a file and add using drupal_add_js()

 Drupal.behaviors.my_module = function (context) {
   // This will load on page load
   ODKL.init();
   // This will attach a click handler to the links
   $('.odkl-klass-stat').click(function() {
   ODKL.Share(this);
   return false;
   }); 
 };
3

http://drupal.org/project/cpn Code per Node is really useful for including Javascript and CSS in seperate text fields.

Have a look

  • Interesting, +1 Didn't know it – corbacho Jul 5 '11 at 10:22
1

Quick and dirty. Put this in the block:

<link href="http://stg.odnoklassniki.ru/share/odkl_share.css" rel="stylesheet">
<script src="http://stg.odnoklassniki.ru/share/odkl_share.js" type="text/javascript" ></script>
<script type="text/javascript" >window.onload=ODKL.init();</script>
<a class="odkl-klass-stat" href="http://preferans.de" onclick="ODKL.Share(this); return false;"><span>0</span></a>

Dirty why? because best practices says to put the css in the <head> to be valid HTML, the scripts in the footer for performance reasons, etc. But it will work.

The best way to do it it's enabling PHP filter and using drupal_add_js, drupal_add_css functions, etc, or create a very simple Drupal module, only with a hook_init to add the js, css and then the block will contain only the a element.

1

For Adsense:

The solution which worked for me is that I used the adsense tags format and then used this format to show ads on the site. Actually I was getting Ads disabled for admin and for other users i was getting the empty ad with space occupied on page but nothing shown. After different tweaks and experiments I got the following code working for me

[adsense:336x280:XXXXXXXXXX]

2nd parameter is width x height 3rd parameter: XXXXXXXXXX denotes the google ad slot/id.

I hope this will help others.

  • His problem isn't with adsense. Read the question.. – rreiss Aug 26 '13 at 21:04
0

The link and the script can be added through drupal_set_html_head() head

drupal_set_html_head('<link href="http://stg.odnoklassniki.ru/share/odkl_share.css" rel="stylesheet"><script src="http://stg.odnoklassniki.ru/share/odkl_share.js" type="text/javascript" ></script>')

The link and the script can be added through drupal_set_html_head() head

drupal_set_html_head('<link href="http://stg.odnoklassniki.ru/share/odkl_share.css" rel="stylesheet"><script src="http://stg.odnoklassniki.ru/share/odkl_share.js" type="text/javascript" ></script>')

Not the answer you're looking for? Browse other questions tagged or ask your own question.