facebook og meta标签有替代品吗?

时间:2014-02-05 13:27:04

标签: php facebook

我在一个页面中列出了

每个活动旁边都有一个facebook分享图标,它必须分享相应事件的标题,描述和图像。但是在这里我不能使用og meta标签,因为所有共享图标都在同一页面中。 我也使用了sharer.php?s = 100%p [title] = test ....但是这也没有显示标题和其他信息。

请帮帮我

1 个答案:

答案 0 :(得分:1)

没有替代方案 - 但是作为解决方法,您可以共享不同的URL,其中更新元标记...

例如 - 对于每个共享图标,将网址指定为http://www.example.com/page/?event=11

然后在您最喜欢的服务器端技术(PHP,ASP,.NET等)中选取事件参数并为每个事件输出适当的OG标记。

-----按照评论中的要求更新以添加PHP示例-----

因此,基于上述建议,您启动每个Facebook共享按钮,使用参数?event = x指定URL,其中x是唯一ID。在PHP中,您可以为每个事件添加一个元标记数组,例如:

$OGTags = array():
$OGTags[1]['description'] = 'This is the description for the first event';
$OGTags[1]['image'] = 'http://www.example.com/image/image.jpg'; // URL for an image related to the first event
$OGTags[2]['description'] = 'This is a description for the second event';
$OGTAgs[2]['image'] = 'http://www.example.com/image/image2.jpg'; // URL for an image related to the second event

然后,您当前输出OG标签的位置需要从阵列中获取内容。

首先检查$ _GET ['event']参数:

$event = isset($_GET['event']) ? $_GET['event'] : '1'; // Use the first descriptor as a default in case parameter not specified

然后在元标记中自己更新,以便从PHP数组中获取值:

<meta property="og:image" content="<?php echo $OGTAgs[$event]['image']" />
<meta property="og:description" content="<?php echo $OGTAgs[$event]['description']" />

这应该可以让你在项目中实现它。