当我点击一个赞按钮时,所有的赞按钮都被赞了,为什么?

When I click one like button all the like buttons are liked why?

我目前正在使用 wordpress 中的 php 访问 json。为了显示类似按钮,我使用简码 echo do_shortcode('[likebtn]'); 在循环中,但不幸的是,当我单击一个喜欢的按钮时,所有喜欢的按钮都被喜欢。

if( ! empty($data1)) {
    echo "Fetching from  " .$data->City." Server".'<br>';
    foreach($data1 as $js){
        echo $js->AIPlatform;
        
        foreach($js->NewsFeed as $pip){
            
            foreach($pip->data as $pr){
                foreach($pr->data as $ar){
                echo '<br>'.$pr->ClusterID.'<br>';
                    echo '<b>'.'<a href="'.$ar->Url.   '" target="_blank";    >'.$ar->text.'</a>'.'<br>'.'</b>';
                    
                    echo '<div class="image">'.'<img src="'.$ar->Image.'"/>'.'</div>'.'<p>'.$ar->Title.'<br>'.'<br>'.'<br>'.'<br>'.'<br>'.'<br>'.'<br>';
                    echo do_shortcode('[likebtn]');
                    
                    
                }
            }
        }
    }

        
                }

当您 post 提问时,请确保 post 尽可能详细。我相信您正在使用名为 LikeBtn. If so, as per the documentation 的插件,它讨论了一个名为 identifier 的参数:

Button identifier parameter is used for statistics analysis. If identifier parameter is not specified, post ID is used.

If specifying custom identifier you will see button identifier in statistics and most liked content widget instead of post title. You also will be unable to sort posts by likes. Make sure to specify a unique identifier for each like button using identifier parameter, otherwise all the buttons will reflect the same number of likes.

所以我猜你的代码是页面上的 运行 或 Post,这使得插件自动获取 Page/Post 的 ID 为 identifier 因为你没有明确地将其传递给简码。因此,当您单击其中一个按钮时,所有类似按钮都会立即更新!

您需要做的是,将唯一 ID 作为 identifier 传递给该简码(在该循环中)。我认为您可以将 $pr->ClusterID 作为 identifier 传递,但我不知道它是否是唯一 ID。如果没有,您必须集思广益,确定要作为 identifier 传递的内容,这将是唯一的(在相同的 Page/Post 上没有重复)

编辑

因此,您可以将回显行更改为如下内容:

echo do_shortcode('[likebtn identifier="'. $pr->ClusterID .'"]');