Facebook喜欢按钮没有链接到正确的URL

问题描述 投票:1回答:2

我有一个包含以下开放图形元标记的网页:

<meta property="fb:admins" content="myid" />
<meta property="og:title" content="myurl.com" />
<meta property="og:url" content="http://www.myurl.com/" />
<meta property="og:description" content="My description" />
<meta property="og:type" content="website" />
<meta property="og:image" content="http://www.myurl.com/images/image.jpg"/>

我试图使用此代码为每个帖子获取Facebook Like按钮:

echo '<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.myurl.com%2Fnews.php%3Fid%3D'.$postid.'&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>';

显然每个喜欢的按钮使用不同的$ postid值,但是当我进入我的网页并且喜欢帖子编号1时,我重新加载页面,而帖子3和4也有新的喜欢。我不像,它是一样的。真的很奇怪,很烦人。这就像连接的帖子没有相同的URL。你知道我怎么解决这个问题?

php facebook button iframe facebook-like
2个回答
1
投票

通过将og:url设置为您网站的基地址,您告诉Facebook这是您想要被喜欢的URL。

在每种情况下使其成为特定帖子的URL。


0
投票

我解决了这个问题,而是在每个帖子的详细信息中添加了一个Like按钮,这样就可以解决在同一页面中有很多Like按钮相互连接的问题。

在详细信息页面(我只使用一个news.php),每次更改URL(具有不同的id)时,og:url参数都以相同的方式更改。

news.php?id=1 has an og:url content="http://www.mysite.com/news.php?id=1"
news.php?id=2 has an og:url content="http://www.mysite.com/news.php?id=2"
and so on...

此外,我相应地更改每个帖子的标题和描述,所以当人们在Facebook上分享它时,它将拥有正确的数据而不是通用的。

如果你想在同一页面上有几个Like按钮,我不知道怎么...

© www.soinside.com 2019 - 2024. All rights reserved.