Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Multiple "Share This" on same page WordPress

  • SOLVED

Hi,

I am using a custom implementation of the share this plugin.
( http://sharethis.com/publishers/getbutton )

Here is the site I am working on: http://67.20.108.233/wordpress/blog

I am using the supplied javascript code to use my own custom graphic instead of the default sharethis button. You will notice on the right side of each blog post there are two buttons. The top button is the custom sharethis button.

The problem I'm running into is that only the first instance of the button is working and all additional buttons do not work. I need your help to be able to add unlimited working buttons to the same page.

I researched this issue some more and it turns out that each subsequent button must use a different variable name. So for example in the javascript code below, the second instance would need "var object2 =" and so on and so forth.

Any help you can provide is greatly appreciated.


<strong>Javascript code that creates custom button</strong>

<script language="javascript" type="text/javascript">
//Create your sharelet with desired properties and set button element to false
var object = SHARETHIS.addEntry({
title:'share',
summary: 'Sharing is good for the soul.'},
{button:false});
//Output your customized button
document.write('<span id="share"><a href="javascript:void(0);" id="share_link"><img src="/my_share_icon.gif" />Share!</a></span>');

//Tie customized button to ShareThis button functionality.
var element = document.getElementById("share");
object.attachButton(element);
</script>





<strong>Here is the wordpress loop form this page: http://67.20.108.233/wordpress/blog</strong>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="blog_content_wrap">
<div class="blog_wrap">
<div class="blog_date">
<h3><?php the_time('j'); ?></h3><h4><?php echo strtoupper(get_the_time('M')); ?></h4>
</div><!-- end blog_date -->

<div class="blog_content">
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<p class="blog_post_info">Posted by: <?php the_author_posts_link(); ?> on <?php the_time('F jS, Y') ?></p>
<?php the_content('Continue Reading &rarr;'); ?>

<?php if (get_the_tags()) : ?>
<div class="tag_wrap">
<p><strong>Tags:</strong> <?php the_tags('', ', '); ?></p>
</div><!-- end tag_wrap -->
<?php endif; ?>
</div><!-- end blog_content -->
</div><!-- end blog_wrap -->

<?php include( TEMPLATEPATH . '/php/nav-sharethis.php' ); ?>
</div><!-- end blog_content_wrap -->


<br class="clear" />
<?php endwhile; else: ?>
<h2>Nothing Found</h2>
<p>Sorry, it appears there is no content in this section.</p>
<?php endif; ?>

<?php wp_pagenavi(); ?>

Answers (2)

2010-07-11

Aneesh Joseph answers:

Use this within the post loop

<script type="text/javascript">
var object<?php the_id();?> = SHARETHIS.addEntry({ title: "<?php the_title();?>", url: "<?php the_permalink();?>" },{button:false});
document.write('<span id="share<?php the_id();?>"><a rel="nofollow" href="javascript:void(0);" id="share_link"><img src="/my_share_icon.gif" />Share!</a></span>');
var element = document.getElementById("share<?php the_id();?>");
object<?php the_id();?>.attachButton(element);
</script>

sorry for the double posting. ignore the reply below.i couldn't delete it :(


Aneesh Joseph comments:

Use this within the post loop

<script type="text/javascript">
var object<?php the_id();?> = SHARETHIS.addEntry({ title: "<?php the_title();?>", url: "<?php the_permalink();?>" },{button:false});
document.write('<span id="share<?php the_id();?>"><a rel="nofollow" href="javascript:void(0);" id="share_link"><img src="/my_share_icon.gif" />Share!</a></span>');
var element = document.getElementById("share<?php the_id();?>");
object<?php the_id();?>.attachButton(element);
</script>

2010-07-11

Rashad Aliyev answers:

I suggest you Addthis sharing plugin.


WP Answers comments:

Thanks but they are stuck on ShareThis so I'd like to explore that option some more.