Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当我点击一个相似的按钮时,所有相似的按钮都是相似的,为什么?_Php_Wordpress_Button_Plugins - Fatal编程技术网

Php 当我点击一个相似的按钮时,所有相似的按钮都是相似的,为什么?

Php 当我点击一个相似的按钮时,所有相似的按钮都是相似的,为什么?,php,wordpress,button,plugins,Php,Wordpress,Button,Plugins,我目前正在wordpress中使用php访问json。对于显示like按钮,我使用的是shortcodeecho do_shortcode(“[likebtn]”) 在循环内部,但不幸的是,当我单击一个相似的按钮时,所有相似的按钮都是相似的 if( ! empty($data1)) { echo "Fetching from " .$data->City." Server".'<br>'; foreach($data1

我目前正在wordpress中使用php访问json。对于显示like按钮,我使用的是shortcodeecho 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]');
                    
                    
                }
            }
        }
    }

        
                }
if(!empty($data1)){
echo“从“$data->City.Server”获取数据“
”; foreach($data1作为$js){ echo$js->aip平台; foreach($js->NewsFeed作为$pip){ foreach($pip->数据为$pr){ foreach($pr->数据为$ar){ 回显“
”。$pr->ClusterID。“
”; 回显''.'.'
'.'''.'; 回显'.'Image'.'/>'.''.'.$ar->Title'.
'.
'.
'.
'.
'.
'.
'; echo do_短码(“[likebtn]”); } } } } }
在发布问题时,请确保发布尽可能多的详细信息。我相信您正在使用名为的插件。如果是这样,根据,它将讨论一个名为
identifier
的参数:

按钮
identifier
参数用于统计分析。如果
标识符
未指定参数,使用了post ID

如果指定自定义
标识符
,您将在中看到按钮标识符 统计信息和最受欢迎的内容小部件,而不是帖子标题 也将无法按喜好对帖子进行排序。请确保指定一个 使用identifier参数的每个like按钮的唯一标识符, 否则,所有按钮将反映相同数量的喜欢。

因此,我猜测你的代码是在一个页面或帖子上运行的,这使得插件自动获取该页面/帖子的id作为
标识符
,因为你没有显式地将其传递给短代码。因此,当你点击其中一个时,所有类似的按钮都会立即更新

你要做的是,将一个唯一的id作为
标识符
传递给那个短代码(在那个循环中)。我认为你可以将
$pr->ClusterID
作为
标识符
传递,但我不知道它是否是唯一的id。如果不是,你必须集体讨论将什么作为
标识符
传递给谁才是唯一的(同一页/帖子上不得重复)

编辑

因此,您可以将回音线更改为以下内容:

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

您好@Ajilesh B chandran我正在使用您已经提到的LikeBtn插件。$pr->ClusterId是一个唯一标识符。我应该如何在程序中使用该标识符?在该短代码行中要做什么更改?@PradeeshwarM编辑了我的答案。请检查