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>";
}


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.