Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to add a VKontakte (pretty much the russian version of Facebook) "like" button to wordpress posts by placing it within the loop along with Twitter/Facebook "like/share" buttons. While this works fine on single posts, on the news overview with excerpt poss the button displays repeatedly on the first post and not on ANY other post.

I'm following these instructions: http://vk.com/developers.php?o=-17680044&p=Like&s=0

I know the issue has to be with something in the javascript messing with the loop and repeating it in one post instead of beneath EVERY post but no idea how to fix it.

Oddly enough their "share" button works absolutely fine.

Any help appreciated as all I so far was able to find about it was in russian...which I don't speak :/

share|improve this question
1  
Where are you inserting that code? Also, check this search results in StackOverflow: stackoverflow.com/search?q=VKontakte –  brasofilo Nov 20 '12 at 22:59
add comment

1 Answer

This isn't WordPress specific, but the code provided on the page you linked places a div with an ID and some javascript that references that ID. If you have multiple instances of this on a single page, you'll have multiple instances of divs and scripts using the same ID, and CSS IDs must be unique.

You can remedy this by adding the post ID to each instance to make them all unique:

<div id="vk_like_<?php echo get_the_ID(); ?>"></div>
<script type="text/javascript">
VK.Widgets.Like("vk_like_<?php echo get_the_ID(); ?>", {type: "full"});
</script>

However, this isn't all you'll need. If you read the text at the bottom of the page:

If the article on your site can have different addresses (for example, depending on the redirecting source, langauge, and other parameters), then in VK.Widgets.Like your internal page identifier 'page_id should be rendered as the last parameter. An example of a code with page_id can be found in the full widget documentation

you'll also need to set a page_id, otherwise all buttons will like the list of posts page rather than the single post page. I'm not able to see the documentation page without a login, so I can only guess that this parameter accepts a permalink.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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