0

我已经使用 octobercms 和插件 rainlab 博客建立了一个博客。现在的问题是我想使用特色图像作为 facebook 共享图像。

如何才能做到这一点?当我转到 Facebook 调试器时,我可以看到徽标和我的特色图片,但一旦我分享它,显示的图片就是徽标。

非常感谢

4

2 回答 2

3

在您用于博客文章的页面/布局中,如果您还没有添加 OpenGraph 标签,则需要添加。

<meta property="og:url" content="http://www.yourwebsite.com" />
<meta property="og:type" content="website" />
<meta property="og:image" content="{{ this.getShareImageUrl }}" />
<meta property="og:title" content="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod" />
<meta property="og:description" content="Lorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati modi illo explicabo quidem ipsa, voluptatum quibusdam, nemo veritatis enim eveniet doloribus et eius voluptate nam cum veniam, fugit. Dolorum, adipisci." />

Facebook 需要这些标签来提取正确的数据。您可能会发现对阅读有关这些标签的更多信息很有用。

因此,您现在只需要正确的特征图像的 url,因为您很可能拥有多个特征图像。您可以根据需要选择编写该逻辑(因此我只是在上面的代码中使用了方法调用),但是一旦您拥有所需的 features_image 的实例,您就可以在实例上使用 getPath() 方法来获取url(因为它是 File 类的一个实例,你可以在上面使用这些方法)。

您可以在此处阅读更多文档 - http://octobercms.com/docs/database/model#file-attachments

就是这样,回到FB调试器并按调试。如果它不起作用,请尝试使用另一个按钮,上面写着“获取新的抓取信息”(仅在您按下调试按钮一次后才会出现),您应该会很好。

我刚刚通过这些步骤创建了一个新网站,我不得不让 facebook 重新抓取以使其正常工作。让我们知道这是否适合您。

于 2015-06-25T07:57:26.320 回答
3

这可能晚了,但我遇到了同样的问题,并使用此代码将图像从您的博客文章页面传递到布局文件:-

function onEnd() {
    $_post = $this->components['blogPost'];
    if ($_post->featured_images->first()) {
        $this->page->og_image = $_post->featured_images->first()->path;
    }
}

这将允许您在布局文件中使用此标记(使用您的<head>in):-

{% if this.page.og_image %}
     <meta property="og:image" content="{{ this.page.og_image }}" />
{% else %}
于 2017-06-14T14:48:53.787 回答