开发者

vBulletin Facebook LIKEs thumbnail

开发者 https://www.devze.com 2023-03-24 11:28 出处:网络
I\'m running vBulletin 4.1.5 and I have configured it\'s Facebook settings. The problem I\'m facing is when someone clicked LIKE button, the thumbnail posted in Facebook is not the first image in the

I'm running vBulletin 4.1.5 and I have configured it's Facebook settings. The problem I'm facing is when someone clicked LIKE button, the thumbnail posted in Facebook is not the first image in the thread, it will pick randomly from anywhere in the page i.e. avatar of any user replied in that thread!

Apprecia开发者_运维技巧te your help!


one solution is that you can define a global "facebook-thumbnail" for all shares.

Go to

  1. AdminCP
  2. Settings
  3. Options
  4. Facebook Options
  5. Image URL

This image should be your site-logo or something else.


I'm still programming with vB3.8.x, however I'm working on a plugin for facebook liking. Might help you write you're own for vB4.x

First, you need opengraph and facebook namespaces defined:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"> 
<head profile="http://gmpg.org/xfn/11"> 

Second, you need facebook's javascript:

<scr ipt type="text/javascript" src="http://connect.facebook.net/en_US/all.js#xfbml=1">
</scr ipt> 

Last, you need open graph tags defined in the section of the html page:

<meta property="og:type" content="article" /> 
<meta property="og:title" content="this shows up as article's title when you like" /> 
<link rel="image_src" href="http://www.yoursite.com/yoursite1.jpg" /> 
<meta property="og:image" content="http://www.yoursite.com/yoursite1.jpg" /> 
<link rel="image_src" href="http://www.yoursite.com/yoursite2.jpg" /> 
<meta property="og:image" content="http://www.yoursite.com/yoursite2.jpg" /> 
<link rel="image_src" href="http://www.yoursite.com/yoursite3.jpg" /> 
<meta property="og:image" content="http://www.yoursite.com/yoursite3.jpg" /> 
<link rel="image_src" href="http://www.yoursite.com/yoursite4.jpg" /> 
<meta property="og:image" content="http://www.yoursite.com/yoursite4.jpg" /> 

The plugin I'm working on will loop through the top 5 attachments for a post and write out image_src tags and og:image tags. Not yet sure which hook I'll use.

pseudo code:

    $attachs = $db->query_read_slave("
            SELECT attachmentid, attachment.dateline 
            FROM " . TABLE_PREFIX . "post AS post
            INNER JOIN " . TABLE_PREFIX . "attachment AS attachment ON (attachment.postid=post.postid AND attachment.visible=1)
            WHERE threadid = $threadinfo[threadid]
                    AND post.visible = 1
            ORDER BY filename DESC
            LIMIT 5
    ");

    if ($db->num_rows($attachs))
    {
            while ($attachment = $db->fetch_array($attachs))
            {
                    $strImages = "<meta property=\"og:image\"  content=\"/attachment.php?attachmentid=$attachment[attachmentid]&d=$attachment[dateline]\" />"
            }
    }

FYI - facebook seems to add thumbnails in a reverse manner. They'll look at the last og:image and use that as the first thumbnail; the next thumbnail shown would be the second to last and so on. Might want to play with the sort order of the SQL if that's important. Also, the image_src link is used for non-open graph social sites (google plus, twitter)

0

精彩评论

暂无评论...
验证码 换一张
取 消