Jump to content

how to handle adding social sharing code to loop in blog code.


webguync

Recommended Posts

Hi, I have some code which displays my blog post in a foreach loop, and I want to add some social sharing code(FB like button, share on Twitter etc.), but the problem is the way I have my code now, creates 3 instances of the sharing buttons, but if you like one post, all three are liked and any thing you do affects all of the blog post. How can I fix this?

 

<?php
include ("includes/includes.php");

$blogPosts = GetBlogPosts();

foreach ($blogPosts as $post)
{
	echo "<div class='post'>";
	echo "<h2>" . $post->title . "</h2>";
	echo "<p class='postnote'>" . $post->post . "</p";
	echo "<span class='footer'>Posted By: " . $post->author . "</span>";
	echo "<span class='footer'>Posted On: " . $post->datePosted . "</span>";
	echo "<span class='footer'>Tags: " . $post->tags . "</span>";
	echo '
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=webguync"></script>';

	echo "</div>";
}


?>

By default AddThis uses the current URL for liking, tweeting, bookmarking, etc.. If you are not using the current URL you must provide that parameter specifically when you make your AddThis links. See their support page here:

 

http://www.addthis.com/help/url-and-title

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.