Answer the question
In order to leave comments, you need to log in
How to propagate the "I like" button from Vkontakte to all posts?
There is such a cycle with the output of posts on the main page posts with standard pagination . It is
necessary that the widget is glued to each post and located under each post and counts the likes for each individual post.
At the moment, the buttons are duplicated as many as there are posts, but all in 1 post
view:
<?php $no = $offset;
foreach ($arr_posts as $pst) {
?>
<div class="row" id="style_posts">
<h2 class="posts-title__style"><?php echo $pst->title ?></h2>
<p class="posts-text__style">
<?php echo $pst->text ?>
</p>
<p><a href="/posts/view/<?php echo $pst->slug ?>" class="btn btn-default pull-right btn_home_posts_down">Комментарии...</a></p>
<p class="posts-time__style">
<span class="post-title-time__style">Добавил, <?php echo $pst->author ?>:</span>
<!-- <span class="like-style" onclick="#"><i class="far fa-thumbs-up"></i></span> -->
<br>
<?php echo $post_date = date("d.m.Y в H:i", strtotime($pst->date)); ?>
</p>
<hr class="hr_left" align="left">
<!-- Put this div tag to the place, where the Like block will be -->
<div id="vk_like"></div>
<script type="text/javascript">
VK.Widgets.Like("vk_like",
{type: "button",
pageTitle: 'Произвольный текст',
pageDescription: 'Всплывающий текст',
pageUrl:'https://mysite.ru'},
666);
</script>
</div>
<?php } ?>
Answer the question
In order to leave comments, you need to log in
Try like this:
<!-- Put this div tag to the place, where the Like block will be -->
<div id="vk_like<?= $pst->id; ?>"></div>
<script type="text/javascript">
VK.Widgets.Like("vk_like<?= $pst->id; ?>",
{type: "button",
pageTitle: 'Произвольный текст',
pageDescription: 'Всплывающий текст',
pageUrl:'https://mysite.ru'},
<?= $pst->id; ?>);
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question