admin 發表於 2018-3-28 18:28:08

Discuz 論壇的$metadescription 修復

使用Discuz X3.4版本後
發現meta中的metadescription有個大問題,
就是只有論壇創始人能看見metadescription
其他人呢?全部看不到
其他人只看的見文章名稱,無法顯示內容。
這無疑對論壇SEO優惠有很大影響。

這問題困擾了我很久,
最後決定自己解決。
為了這個我下載Fileseak去搜尋php檔案內的字。


先搜尋$metadescription後發現程式碼都正常
不過發現這也跟$summary變數有關,
if(!$metadescription) {
        $metadescription = $summary.' '.strip_tags($_G['forum_thread']['subject']);
}

改搜$summary後,發現有一行字很怪,
檔案source\module\forum\forum_viewthread.php
if(!$_G['forum_thread']['price'] && (IS_ROBOT || $_G['adminid'] == 1)) $summary = str_replace(array("\r", "\n"), '', messagecutstr(strip_tags($post['message']), 160));

發現這是一個很大的問題,
只有IS_ROBOT 或是adminid為 1的人才能看到$summary
也就是$metadescription
因此我決定將它刪掉或註解ˋ掉
註解ˋ掉變成
//if(!$_G['forum_thread']['price'] && (IS_ROBOT || $_G['adminid'] == 1))
                        $summary = str_replace(array("\r", "\n"), '', messagecutstr(strip_tags($post['message']), 160));
記得後面要換行,不然會連$summary一起註解,

刪掉就是直接變成
$summary = str_replace(array("\r", "\n"), '', messagecutstr(strip_tags($post['message']), 160));
之後......果然解決了
頁: [1]
查看完整版本: Discuz 論壇的$metadescription 修復