利用文字链接添加关键词和链接,这样方便管理。
下面请看具体步骤:
1.在common/incfiles/inc.asp中添加一个函数:
Function kreplace(str)
dim tcontent,k1,k2,rs
if str = "" then exit function
tcontent = str
sqlstr = "select * from jtbc_support_linktext"
Set rs = conn.Execute(sqlstr)
do while not rs.eof
k1 = rs("l_topic")
k2 = rs("l_url")
tcontent = Replace(tcontent, k1, "<a href=""" & k2 & """ target=""_blank"">"& k1 &"</a >",1,3)
rs.movenext
loop
Set rs = Nothing
kreplace = tcontent
end function
其中sqlstr = "select * from jtbc_support_linktext" 是通过查询文本链接数据库jtbc_support_linktext来实现关键字和链接的替换。
其中tcontent = Replace(tcontent, k1, "<a href=""" & k2 & """ target=""_blank"">"& k1 &"</a >",1,3) 最后的数字3是限制同一关键字只替换3次。
2.在公共管理,文本链接中添加对应的关键字和链接即可。
3.在需要实现自动添加关键词内链的模块/baike/common/incfiles/module_config.asp文件中,在Function jtbc_cms_module_detail()中把以下代码
tmpstr = Replace(tmpstr, "{$content}", encode_content(cutepage_content(rs(cfname("content")), rs(cfname("cp_note")), rs(cfname("cp_mode")), rs(cfname("cp_type")), rs(cfname("cp_num"))), rs(cfname("cttype"))))
修改成:
tmpstr = Replace(tmpstr, "{$content}", kreplace(encode_content(cutepage_content(rs(cfname("content")), rs(cfname("cp_note")), rs(cfname("cp_mode")), rs(cfname("cp_type")), rs(cfname("cp_num"))), rs(cfname("cttype")))))
对应的修改需要实现此功能的模块,即可实现。