Answer the question
In order to leave comments, you need to log in
How to share VK comments?
Hello! Faced a problem. There are 2 VK comment widgets on the page. One in one block, the second in another. But for some reason they are all displayed in one block. How to decide?
<ul class="hidden-menu">
<script type="text/javascript" src="//vk.com/js/api/openapi.js?133"></script>
<script type="text/javascript">
VK.init({apiId: 5604749, onlyWidgets: true});
</script>
<div id="vk_comments"></div>
<script type="text/javascript">
VK.Widgets.Comments("vk_comments", {limit: 10, width: "210", attach: "*", autoPublish: "0", pageUrl: "http://rz34.ru"});
</script>
</ul>
<div class="entry-content">
<p><script type="text/javascript" src="//vk.com/js/api/openapi.js?127"></script><br />
<script type="text/javascript">
VK.init({apiId: 5604749, onlyWidgets: true});
</script></p>
<p><!-- Put this div tag to the place, where the Comments block will be --></p>
<div id="vk_comments"></div>
<p><script type="text/javascript">
VK.Widgets.Comments("vk_comments", {redesign: 1, limit: 20, width: "1060", attach: "*"});
</script></p>
</div>
Answer the question
In order to leave comments, you need to log in
The attribute id
implies the uniqueness of the element, therefore, there cannot be two elements on the page with the same ID. The method VK.Widgets.Comments()
takes this very element ID as the first parameter. You need to do something like this:
First comment block:
<div id="vk_comments_1"></div>
<script type="text/javascript">
VK.Widgets.Comments("vk_comments_1", {redesign: 1, limit: 20, width: "1060", attach: "*"});
</script>
<div id="vk_comments_2"></div>
<script type="text/javascript">
VK.Widgets.Comments("vk_comments_2", {redesign: 1, limit: 20, width: "1060", attach: "*"});
</script>
VK.Widgets.Comments()
pass the third parameter with a unique ID to the method, otherwise the VK will display the same comments in both widgets. For example, you can put a number for the first widget 1
, and a number for the second. 2
What is it and why is it needed, I answered here: How to make a chat from VK comments? (see comments on answer).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question