在文章模块中,每个网页Head部分的“keywords,title,description”是一成不变的。如果我们要在发布每一篇文章的时候就顺便自定义每篇文章的“keywords,title,description三个元素的内容该咋办了?
在JT的指导下,通过自己改程序实现了目标,下面就请各位跟着我来看看是怎么操作的吧!
以“article”模块做实例:
第一步:添加字段
1、打开网站根目录下的common\database文件夹,打开“#db.asa”数据库文件,找到“article”数据表,在数据表中添加三个字段,分别是“a_keywords,a_title,a_description”,字段的数据类型是“文本”。
注:a_”是前缀,不同模块的前缀不同,文章模块里是“
d_”。
第二步:在language里增加相对应的文字显示
1、打开网站根目录下common\language文件夹,打开lng_config.jtbc,往里面增加如下内容:
[p] <item>
<disinfo><![CDATA[
keywords]]></disinfo>
<chinese><![CDATA[
网页关键字]]></chinese>
</item>[/p]
[p] <item>
<disinfo><![CDATA[
title]]></disinfo>
<chinese><![CDATA[
网页标题]]></chinese>
</item>[/p]
[p] <item>
<disinfo><![CDATA[
description]]></disinfo>
<chinese><![CDATA[
网页描述]]></chinese>
</item>[/p]
第三步:修改后台处理函数
1、打开"article\common\incfiles"目录,用记事本打开manage_config.asp文件。
2、找到Sub jtbc_cms_admin_manage_adddisp()这个函数,在rs.Update前增加如下内容:
rs(cfname("keywords")) = left_intercept(get_str(request.Form("keywords")),150)
rs(cfname("title")) = left_intercept(get_str(request.Form("title")), 150)
rs(cfname("description")) = left_intercept(get_str(request.Form("description")),150)
3、找到Sub jtbc_cms_admin_manage_editdisp()函数,在rs.Update前增加如下内容:
rs(cfname("keywords")) = left_intercept(get_str(request.Form("keywords")),150)
rs(cfname("title")) = left_intercept(get_str(request.Form("title")), 150)
rs(cfname("description")) = left_intercept(get_str(request.Form("description")),150)
第四步:后台添加和修改
1、打开“article\common\template”文件夹,打开“manage.jtbc”文件。
[p] 2、找到<name><![CDATA[
add]]></name>节点,在合适的地方添加如下内容:[/p]
<tr>
<td width="80" height="25">{$=itake('global.lng_config.title','lng')}</td>
<td width="*"><input type="text" name="title" size="60"></td>
</tr>
<tr>
<td width="80" height="25">{$=itake('global.lng_config.keywords','lng')}</td>
<td width="*"><input type="text" name="keywords" size="60"></td>
</tr>
<tr>
<td width="80" height="25">{$=itake('global.lng_config.description','lng')}</td>
<td width="*"><textarea rows="5" name="description" cols="60"></textarea></td>
</tr>
[p]
3、找到<name><![CDATA[
edit]]></name>节点,在合适的地方添加如下内容:[/p]
<tr>
<td width="80" height="25">{$=itake('global.lng_config.title','lng')}</td>
<td width="*"><input type="text" name="title" size="60" value="{$title}"></td>
</tr>
<tr>
<td width="80" height="25">{$=itake('global.lng_config.keywords','lng')}</td>
<td width="*"><input type="text" name="keywords" size="60" value="{$keywords}"></td>
</tr>
<tr>
<td width="80" height="25">{$=itake('global.lng_config.description','lng')}</td>
<td width="*"><textarea rows="5" name="description" cols="60">{$description}</textarea></td>
</tr>
第五步、
自定义输出标签(关键所在)
1、打开“article\common\incfiles”文件夹,打开“module_config.asp”文件。
2、找到“Function jtbc_cms_module_detail()”函数,在该函数中“
tmpstr = creplace(tmpstr)
”语句后添加如下内容:
tmpstr = Replace(tmpstr, "{$title}", htmlencode(get_str(rs(cfname("title")))))
tmpstr = Replace(tmpstr, "{$keywords}", htmlencode(get_str(rs(cfname("keywords")))))
tmpstr = Replace(tmpstr, "{$description}", htmlencode(get_str(rs(cfname("description")))))”
第六步、添加自定义头部模板
1、打开网站根目录下的“common\template”文件夹,打开“tpl_public.jtbc”文件。
2、 添加如下自定义头部模板节点内容:
[p]<name><![CDATA[self_define_head]]></name>
<tpl_default><![CDATA[[/p]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
{$=web_base()}
<meta http-equiv="x-ua-compatible" content="IE=EmulateIE7" />
<meta name="robots" content="all" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-cn" />
<meta name="keywords" content="{$keywords}" />
<meta name="description" content="{$description}" />
<title>{$title}</title><script type="text/javascript" src="{$global.images}js/main.js"></script>
<script type="text/javascript" src="{$global.images}js/writeflashhtml2.js"></script>
<link type="text/css" rel="stylesheet" href="{$global.images}theme/{$=nskin}/layout.css" />
</head>
]]></tpl_default>
</item>
第七步、修改前台详情页面所调用的头部模板
1、打开"article\common\template"文件夹,打开“module.jtbc”文件。
[p] 2、找到“<name><![CDATA[detail]]></name>”节点,修改节点内容中的“{$=web_head(nhead)}”为
“{$=web_head('self_define_head')}”。(也就是把默认的头部模板名修改为你刚才添加的那个头部模板名)[/p]
经过以上的七个步骤,在添加文章的时候,就可以自定义“keywords,title,description”的内容了。当然其他模块需要此功能也可以这样添加。
实例网站:
http://www.nnhuibo.com/hbnews
如果还有什么问题,可以加我Q:5757663,一起交流学习。