我正在尝试为我的博客文章创建一个Facebook共享选项,它可以工作,但它不需要文章文本或图像,而是(单页)网站上的第一个图像和文本。如何更改我的共享代码,以便它使用文章的图像和文本,从中单击FB共享按钮?
这是博客文章的模板,其中包含FB共享代码:
<div class="contentLeft">
<div class="roundimage">
<a href="[[+roundImage:phpthumbof=`h=750&zc=1`]]" class="colorbox" title="[[+roundImageCaption]]"><img class="round"
src="[[+roundImage:phpthumbof=`w=170&h=170&zc=1&q=95`]]" alt="[[+roundImageCaption]]" /></a>
</div>
<script type="text/javascript">function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script><a href="http://www.facebook.com/share.php?u=[(site_url)][~[*id*]~]" onclick="return fbs_click()" target="_blank" class="fbsharebutton"></a>
<h4 class="blue" style="margin-bottom:10px; margin-top:0;">[[+articleHeadline]]</h4>
<p class="datetext">[[+datetimeText]]</p>
<p class="readmoretext">[[+articleText]]</p>
<div class="divider"></div>
</div>
希望你能帮忙!谢谢!
答案 0 :(得分:0)
确保文章页面(即您共享的链接)嵌入正确的og:image和og:description应该足够了。您只与分享按钮共享链接,Facebook将嵌入链接并查看其中的正确数据。
<强>更新强>: 我猜您是不是不使用文章包来创建博客?如果您已经拥有单独的页面,即使您没有使用它们=)如果您不认为您正在使用某种资源循环来创建条目。
在浏览facebook文档后,您似乎可以在使用javascript sdk(https://developers.facebook.com/docs/opengraph/using-actions/v2.0#params)创建共享按钮时指定图像(https://developers.facebook.com/docs/sharing/reference/share-dialog)。每篇文章都需要调用类似这样的内容而不是当前的javascript共享网址功能。
FB.ui({
method: 'share_open_graph',
action_type: 'og.likes',
action_properties: JSON.stringify({
image: "YourImageForThisRespectiveShare",
})
}, function(response){});
如果您希望探索我在评论中提到的方法,它将会是这样的:
查看代码u=location.href;
,您想尝试将其修改为u=location.href+'?articleid=[~[*id*]~]';
。当您分享时,您应该希望看到每篇文章的附加文章ID。
然后你需要确保你可以为每篇文章指定og:image和description,我假设你以某种方式设置了代表每篇文章的资源,在这种情况下只需为它创建几个模板变量资源类型。
然后,您可以在标题中使用getResourceField
包从正确的资源中检索正确的电视,具体取决于您网址中的?articleid=
参数。
要检索参数,您需要一个简单的代码段return (!empty($_GET['articleid']) ? $_GET['articleid'] : $default);
。让我们给代码片段命名:&#34; getArticleId&#34;。当没有指定&amp; articleid时,我离开了选项来决定默认图像。
您从[~[*id*]~]
标记的外观中使用了modx evolution,但是应该有一些等同于进化的getResourceField包。这是所需代码的革命版本:
<meta property="og:image" content="[[!getResourceField?
&id=`[[!getArticleId? &default=`[[*id]]`]]` //Take the blog page's own image as a default
&field=`imageTV` //you'll of course have to change "imageTV" to whatever you call it
&isTV=`1`
]]" />
重复og:title和og:description,以及各自的电视名称。