How to set pictures from the post as thumbnail for Facebook feed?

time

Active member
#21
Hi Jake,
when you copy the url of thread (no image in content) and post it in fb,
it will display the random image on the website. You can help me fix the poster's avatar.

Thanks
 

TheBigK

Well-known member
#25
Hi @Jake Bunce - I tried this with thread_view and xenporta articles; using template edits. It still picks up the avatar instead of the the attachment. I'm serving all my images through CDN from url (data.crazyengineers.com) - could that be an issue?
 

Jake Bunce

XenForo moderator
Staff member
#26
Hi @Jake Bunce - I tried this with thread_view and xenporta articles; using template edits. It still picks up the avatar instead of the the attachment. I'm serving all my images through CDN from url (data.crazyengineers.com) - could that be an issue?
Check the page source code for <meta property="og:image"
 

Saburov

Active member
#27
This code is a little ugly. I couldn't find a way to access the first attachment from $firstPost.attachments without using foreach. There may be an easier way, but this code works in my testing. Also... I have since discovered that this code only works on the first page of the thread. Or rather, it pulls the first attachment from the first post on the current page.

I came up with this template edit that sets the thumbnail of the first attachment in the first post as an og:image. Otherwise it will fall back to using the avatar of the thread author which it already does by default.

Edit this template:

Admin CP -> Appearance -> Templates -> thread_view

Replace this code:

Code:
<xen:container var="$head.openGraph"><xen:include template="open_graph_meta">
        <xen:set var="$url">{xen:link 'canonical:threads', $thread}</xen:set>
        <xen:set var="$title">{$thread.title}</xen:set>
        <xen:set var="$avatar">{xen:helper avatar, $thread, m, 0, 1}</xen:set>
    </xen:include></xen:container>
With this:

Code:
<xen:comment>extract first thumbnail URL from first post, for use in open_graph_meta below</xen:comment>
<xen:if is="{$firstPost.attachments}">
    <xen:foreach loop="$firstPost.attachments" value="$attachment" i="$i" count="$count">
        <xen:if is="{$i} == 1 AND {$attachment.thumbnailUrl}">
            <xen:set var="$ogThumb">{xen:helper fullurl, $attachment.thumbnailUrl, 1}</xen:set>
        </xen:if>
    </xen:foreach>
</xen:if>

<xen:container var="$head.openGraph"><xen:include template="open_graph_meta">
        <xen:set var="$url">{xen:link 'canonical:threads', $thread}</xen:set>
        <xen:set var="$title">{$thread.title}</xen:set>
        <xen:set var="$avatar"><xen:if is="{$ogThumb}">{$ogThumb}<xen:else />{xen:helper avatar, $thread, m, 0, 1}</xen:if></xen:set>
    </xen:include></xen:container>
For referenece:

http://xenforo.com/community/threads/changing-og-image-thumbnail.17141/

doesn't work
 
#28
This code is a little ugly. I couldn't find a way to access the first attachment from $firstPost.attachments without using foreach. There may be an easier way, but this code works in my testing. Also... I have since discovered that this code only works on the first page of the thread. Or rather, it pulls the first attachment from the first post on the current page.

I came up with this template edit that sets the thumbnail of the first attachment in the first post as an og:image. Otherwise it will fall back to using the avatar of the thread author which it already does by default.

Edit this template:

Admin CP -> Appearance -> Templates -> thread_view

Replace this code:

Code:
<xen:container var="$head.openGraph"><xen:include template="open_graph_meta">
        <xen:set var="$url">{xen:link 'canonical:threads', $thread}</xen:set>
        <xen:set var="$title">{$thread.title}</xen:set>
        <xen:set var="$avatar">{xen:helper avatar, $thread, m, 0, 1}</xen:set>
    </xen:include></xen:container>
With this:

Code:
<xen:comment>extract first thumbnail URL from first post, for use in open_graph_meta below</xen:comment>
<xen:if is="{$firstPost.attachments}">
    <xen:foreach loop="$firstPost.attachments" value="$attachment" i="$i" count="$count">
        <xen:if is="{$i} == 1 AND {$attachment.thumbnailUrl}">
            <xen:set var="$ogThumb">{xen:helper fullurl, $attachment.thumbnailUrl, 1}</xen:set>
        </xen:if>
    </xen:foreach>
</xen:if>

<xen:container var="$head.openGraph"><xen:include template="open_graph_meta">
        <xen:set var="$url">{xen:link 'canonical:threads', $thread}</xen:set>
        <xen:set var="$title">{$thread.title}</xen:set>
        <xen:set var="$avatar"><xen:if is="{$ogThumb}">{$ogThumb}<xen:else />{xen:helper avatar, $thread, m, 0, 1}</xen:if></xen:set>
    </xen:include></xen:container>
For referenece:

http://xenforo.com/community/threads/changing-og-image-thumbnail.17141/
On xen 1.4.3 don't work
 

otto

Well-known member
#30
It works with 1.5.x ! I have made it in two forums and it works.

In my case, I use the attach thumbnails for OG:Image, but these must be min. 200 x 200 pixel! After I set my Thumbnail size to "356" (Pixel, 16:9; 356 x 201 px) I can see the attachment thumbnails on Facebook.


IMG and ATTACH can filtered out with a hint from BobbyWibowo, you can find here: https://xenforo.com/community/threa...om-page-meta-descriptions.67738/#post-1069719

Thats all what we have to do, to do the job we want. :)
Thanks to Jake Bunce and BobbyWibowo for his hints, it works also with latest Xenforo 1.5.12.
 
Top