Для многих не секрет, что публикация ваших записях в социальных медиа добавит трафик для вашего сайта или портала. Но чтобы запись легко было публиковать в социальной сети, то делаются специальные кнопки. Есть бесплатный сервис, генерирующий скрипт, который позволяет посетителям вашего сайта публиковать ссылки на ваши статьи в социальные медиа (закладки, социальные сети). Сервис называется share42 — скрипт кнопок социальных закладок и сетей. И сейчас я расскажу как его поставить на сайт, который работает на движке drupal.
Вначале идем на сайт share42.com.
В генераторе выбираем нужные кнопки и некоторые опции, а потом нажимаем скачать готовый скрипт.
Теперь будем заниматься его установкой.
Вначале его надо распаковать. Полученную папку «share42» копируем на сайт по FTP по адресу ./sites/all/libraries (при желании папку можно переименовать).
У нас должно получится что-то похожее на это: http://site.ru/share42/.
Код ниже может отличаться. На сайте приведен код для любого сайта:
<div class="share42init"></div>
<script type="text/javascript" src="http://site.ru/share42/share42.js"></script>
<script type="text/javascript">share42('http://site.ru/share42/')</script>Но нас интересует именно друпал
<div class="share42init" data-url="<?php print $node_url ?>" data-title="<?php print $title ?>"></div>
<script type="text/javascript" src="http://site.ru/share42/share42.js"></script>
<script type="text/javascript">share42('http://site.ru/share42/')</script>Но данный код работает не совсем корректно, в нем надо кое-что исправить, а именно
<?php print $node_url ?>
меняем на
<?php print 'http://site.ru'.$node_url ?>
Т.е. в код который надо вставить:
<div data-url="<?php print $node_url ?>" data-title="<?php print 'http://site.ru'.$node_url ?>"></div>
<script type="text/javascript" src="http://site.ru/share42/share42.js"></script>
<script type="text/javascript">share42('http://site.ru/share42/')</script>Теперь его надо вставить в шаблон. Будем его вставлять в файл «node.tpl.php», у меня в шаблоне код такой:
<?php
?>
<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>>
<?php print $user_picture; ?>
<?php print render($title_prefix); ?>
<?php if (!$page): ?>
<h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>
<?php endif; ?>
<?php print render($title_suffix); ?>
<?php if ($display_submitted): ?>
<span class="submitted"><?php print $submitted ?></span>
<?php endif; ?>
<div class="content clearfix"<?php print $content_attributes; ?>>
<?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
print render($content);
?>
</div>
<div class="clearfix">
<?php if (!empty($content['links'])): ?>
<div class="links"><?php print render($content['links']); ?></div>
<?php endif; ?>
<?php print render($content['comments']); ?>
</div>
</div>Код вставляем перед комментариями перед <div class=»clearfix»> и получаем:
<?php
?>
<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>>
<?php print $user_picture; ?>
<?php print render($title_prefix); ?>
<?php if (!$page): ?>
<h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>
<?php endif; ?>
<?php print render($title_suffix); ?>
<?php if ($display_submitted): ?>
<span class="submitted"><?php print $submitted ?></span>
<?php endif; ?>
<div class="content clearfix"<?php print $content_attributes; ?>>
<?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
print render($content);
?>
</div>
<!-- Share42 -->
<?php if ($page): ?>
<div class="share42init" data-url="<?php print 'http://site.ru'.$node_url ?>" data-title="<?php print $title ?>"> </div>
<script type="text/javascript" src="http://site/sites/all/libraries/share42/share42.js"></script>
<script type="text/javascript">share42('http://site/sites/all/libraries/share42/')</script>
<?php endif; ?>
<!-- /Share42 -->
<div class="clearfix">
<?php if (!empty($content['links'])): ?>
<div class="links"><?php print render($content['links']); ?></div>
<?php endif; ?>
<?php print render($content['comments']); ?>
</div>
</div>










Интересная статья, но думаю стоит описать что папку share24 Вы перекинули в ../sites/all/libraries
Да, все верно. Спасибо за указание ошибки.