วิธีแชร์ภาพให้ขึ้นบน Facebook สำหรับ Discuz! X3.2
แก้ไขครั้งสุดท้ายโดย viwatchai เมื่อ 2017-1-3 23:35จากปัญหาแชร์ภาพให้ขึ้นบน Facebook เท่าที่ลองไม่สามารถใช้กับ Discuz! X3.2 ได้นั้น
วิธีแชร์ facebook ให้ภาพขึ้น
หลังจากที่ลองผิดลองถูกมาพักใหญ่ คิดว่าน่าจะแก้ปัญหาเรื่องนี้ได้ตามที่ผมตามหาวิธีมานาน
ส่วนที่ 1 ให้แก้ไฟล์ common/header_common.htm
วิธีแก้ให้เข้าไปที่สกินที่ใช้แล้วหา common/header_common.htmแล้วเปิดขึ้นมา หาแท็ก <meta>ล่าสุด
ดังภาพนะครับ
นำโค๊ตด้านล่างไปใส่ได้เลยครับ
<!--{if $_G['tid']}-->
<meta property="og:type" content="website"/>
<!--{if in_array('forum_viewthread', $_G['setting']['rewritestatus'])}-->
<meta property="og:url" content="$_Gthread-{$_G}-1-1.html"/>
<!--{else}-->
<meta property="og:url" content="$_Gforum.php?mod=viewthread&tid=$_G"/>
<!--{/if}-->
<meta property="og:title" content="$navtitle"/>
<meta property="og:description" content="{if !empty($metadescription)}{echo htmlspecialchars($metadescription, ENT_QUOTES, 'UTF-8')}{/if}"/>
<!--{if $_G['iattrs']}-->
<meta property="og:image" content="$_G"/>
<!--{/if}-->
<meta property="og:site_name" content="$_G"/>
<meta property="fb:app_id" content=""/>
<meta itemprop="name" content="$navtitle">
<meta itemprop="description" content="{if !empty($metadescription)}{echo htmlspecialchars($metadescription, ENT_QUOTES, 'UTF-8')}{/if}">
<!--{eval $ogImageStop = false; $key = 0;}-->
<!--{loop $postlist $post}-->
<!--{loop $post['attachments'] $attachment}-->
<!--{if $attachment['isimage']}-->
<!--{eval $key++}-->
<!--{if $key < 2}-->
<meta property="og:image" content="{$_G['siteurl']}{$attachment['url']}{$attachment['attachment']}">
<!--{/if}-->
<!--{eval $ogImageStop = true;}-->
<!--{/if}-->
<!--{/loop}-->
<!--{/loop}-->
<!--{elseif CURSCRIPT == 'forum' && !$_G['mod']}-->
<meta property="og:type" content="website"/>
<meta property="og:url" content="$_G"/>
<meta property="og:title" content="$_G"/>
<meta property="og:description" content="{if !empty($metadescription)}{echo htmlspecialchars($metadescription, ENT_QUOTES, 'UTF-8')}{/if}"/>
<meta property="og:image" content="$_G"/>
<meta property="og:site_name" content="$_G"/>
<meta property="fb:app_id" content=""/>
<meta itemprop="name" content="$_G">
<meta itemprop="description" content="{if !empty($metadescription)}{echo htmlspecialchars($metadescription, ENT_QUOTES, 'UTF-8')}{/if}">
<meta itemprop="image" content="$_G">
<!--{/if}-->
ส่วนที่ 2 ปรับ ในส่วนของ admincp
ให้เข้าไปที่/admin.php?frames=yes&action=setting&operation=styles&anchor=viewthread
หาคำว่า Guest view thumbnails: เลือก ใช่
แล้วกดตกลงด้านล่าง
ดังภาพนะครับ
ส่วนที่ 3 ปรับความยาวของ description
อ้างอิงจากกระทู้นี้ ของคุณ gu_1n นะครับ
แก้บัคแวลาแชร์กระทู้ลงเฟสบุคแล้ว Description ของกระทู้ซ้ำกับ Title ของกระทู้
หาไฟล์ : source/function/function_core.php
แก้ไขบรรทัดที่ 309 จาก :
static $kw_spiders = array('bot', 'crawl', 'spider' ,'slurp', 'sohu-search', 'lycos', 'robozilla');
เปลี่ยนเป็น
static $kw_spiders = array('bot', 'crawl', 'spider' ,'slurp', 'sohu-search', 'lycos', 'robozilla', 'facebookexternalhit');
หาไฟล์ : source/module/forum/forum_viewthread.php
แล้วหาบรรทัดที่ประมาณ 660
if(!$_G['forum_thread']['price'] && (IS_ROBOT || $_G['adminid'] == 1)) $summary = str_replace(array("\r", "\n"), '', messagecutstr(strip_tags($post['message']), 160));
แล้วแก้เป็น
$summary = str_replace(array("\r", "\n"), '', messagecutstr(strip_tags($post['message']), 160));
หรือ ลบ
if(!$_G['forum_thread']['price'] && (IS_ROBOT || $_G['adminid'] == 1))
หมายเหตุ ตัวเลข 160 คือความยาวของจำนวน description ที่เราต้องการให้แสดงนะครับ
อ้างอิง :
วิธีแก้เมื่อแชร์กระทู้ใน facebook แล้วภาพไม่ขึ้น
แก้บัคแวลาแชร์กระทู้ลงเฟสบุคแล้ว Description ของกระทู้ซ้ำกับ Title ของกระทู้ ยอดเยี่ยม ต้องลอง แก้ไขครั้งสุดท้ายโดย tangshop เมื่อ 2018-2-8 09:57
รองทำตามที่ เขียนบอกไว้หมดแล้วครับ รูปไม่ขึ้นนะครับทั้ง 3 ไฟล์
เพิ่มเติม
คลิ๊กhttps://discuzthai.com/thread-38455-1-1.html
https://discuzthai.com/thread-38455-1-1.html 3.3 ใช้ได้หรือป่าวครับ
หน้า:
[1]