近日,用Discuz X2新开了一个网站,把门户设置成了首页,内容均取自论坛。
在管理员登录状态下,门户首页和论坛首页都能正常看到SEO相关内容(keywords和description),但在未登录状态下,即仅仅是游客的情况下,门户首页的SEO只显示"门户",即:
<meta name="keywords" content="门户" />
<meta name="description" content="门户" />
经过自身试验,找到了一个解决办法。
通过修改 source/class/helper/helper_seo.php 文件。
找到以下内容(以discuz x2.5 为例,在helper_seo.php文件第38行):
if($descriptiontext && (CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
$seodescription = strreplace_strip_split($searchs, $replaces, $descriptiontext);
}
if($keywordstext && (CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
$seokeywords = strreplace_strip_split($searchs, $replaces, $keywordstext);
}
修改成方案一:
if($descriptiontext && ( CURSCRIPT == 'portal' ||CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
$seodescription = strreplace_strip_split($searchs, $replaces, $descriptiontext);
}
if($keywordstext && ( CURSCRIPT == 'portal' ||CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
$seokeywords = strreplace_strip_split($searchs, $replaces, $keywordstext);
}
或者
修改成方案二:
if($descriptiontext) {
$seodescription = strreplace_strip_split($searchs, $replaces, $descriptiontext);
}
if($keywordstext) {
$seokeywords = strreplace_strip_split($searchs, $replaces, $keywordstext);
}
红色部分所示为代码修改的部分。
(责任编辑:admin) |