0

I'm using Sharethis, is there any way to show sharethis as horizontal counter on the articles content type teaser display and then show it as large chicklets on a block?

1
  • 1
    Neither "horizontal counter", not "large chicklets", makes sense to me.
    – Letharion
    Commented Feb 14, 2013 at 9:09

2 Answers 2

1

You can do it in node.tpl file, by using the sharethis custom code(get it from sharethis.com) and choose your horizontal style

below is the code to display only in teaser(paste this code in node.tpl)

<?php if ($teaser): ?>            
    <span class='st_email_hcount' displayText='Email'></span>
    <span class='st_sharethis_hcount' displayText='ShareThis'></span>
    <span class='st_plusone_hcount' displayText='Google +1'></span>
    <span class='st_facebook_hcount' displayText='Facebook'></span>
    <span class='st_twitter_hcount' displayText='Tweet'></span>
    <span class='st_linkedin_hcount' displayText='LinkedIn'></span>
<?php endif;?>

for block again choose your style from sharethis.com and paste it in the block

hope you can get ideas from the above!

1
  • Thank you for this great answer... But I think it's more easy to me to put this code in the block. And set sharethis module to show on every node in its configuration page. thanks again
    – jramby
    Commented Feb 14, 2013 at 10:39
0

I think you can implement this using hook_node_view().

Make ShareThis settings as block at admin/config/services/sharethis by choosing the button style Large Chicklets and choosing Context » Location » Block.

To display the ShareThis in the node view, you would need to implement hook_node_view(). The ShareThis module has sharethis_node_view().

Copy sharethis_node_view() and rename it to mymodule_node_view(). Then, update it as you need. The main trick is $data_options['buttons'] = 'stbc_hcount'; which shows horizonal counters buttons.

function mymodule_node_view($node, $view_mode = 'full', $langcode = NULL) {
    if($view_mode == 'full'){       
      // First get all of the options for the sharethis widget from the database:
      $data_options = sharethis_get_options_array();
      // horizonal country button type
      $data_options['buttons'] = 'stbc_hcount';

      // This looks to see if the path variable has been posted by some rewrite module.
      // This is not super efficient, O(N), but N is often less than 20.
      $is_path = FALSE;
      foreach ($node as $k => $v) {
        if ($k == "path") {
          $is_path = TRUE;
        }
      }
      // This will choose the path to use.
      if ($is_path) {
        $path_module = $node->path;
      }
      else {
        $path_module = "/node/" . $node->nid;
      }

      // Pathauto integration !
      if (module_exists('pathauto')) {
        $path_module = '/' . drupal_lookup_path('alias',"node/" . $node->nid);
      }

      global $base_url;
      // Get the full path to insert into the Share Buttons.
      $mPath = $base_url . $path_module;
      $mTitle = $node->title;

      // Only display the ShareThis buttons if this node fits all the requirements
      if (strpos($data_options['nodeType'], $node->type) !== FALSE) { // Make sure this is the right type of node.
        if (($data_options['viewMode'] == "1") && ($view_mode == "teaser")) { 
          // If "don't show for teaser" is enabled, and this is a teaser, don't do anything
          // Do nothing.
        } 
        else {
          // Check where we want to display the ShareThis widget.             
          $node->content['sharethis'] = array(
            '#tag' => 'div', // Wrap it in a div.
            '#type' => 'html_tag',
            '#attributes' => array('class' => 'sharethis-buttons'),
            '#value' => sharethis_get_button_HTML($data_options, $mPath, $mTitle),
            '#weight' => intval(variable_get('sharethis_weight', 10)),
          );
        }
      }     
    }   
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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