本来想写一个ZBLOG的“相关文章”插件,但上网一搜索,发现已经有人写过了。我就直接拿来用了。粗略用了一下,发现其耗费资源很大,每生成一篇文章都要多执行2条数据库查询,使得重建文章速度更慢了。这和我以前想的方法不一样,我想的方法应该是先将全部TAG生成独立的临时文件 ,在文章重建的时候再进行文本替换,这样执行的数据库查询就很少了,不会占用太多系统资源,可惜现在没时间去实现。
下面是七夜发布的Z-blog“相关文章”修改方法,其中Export_Mutuality处代码我进行了一些修改,使得TAG为空的时候该代码也能正常运行。原文地址参见:http://www.h2o.name/post/661.html
1.新增加一个模板,名字为b_article_mutuality.html,文章扩展名根据情况修改,内容
<li class="mutualityurl"><a href="<#article/mutuality/url#>.html"><#article/mutuality/name#></a> (<#article/mutuality/posttime#>)</li>
2.b_article-single.html增加如下内容,具体位置自己选
<ul class="msg trackback">
<li class="tbname">相关文章</li>
<#template:article_mutuality#>
</ul>
3.CSS样式增加一个,具体根据自己喜好修改,内容如下
li.mutualityurl{
text-align:left;
padding:3px 10px 0px 10px;
margin:0;
background:#F6F4EE;
line-height:150%;
}
4.c_system_base.asp的Function LoadGlobeCache()部分,原来的几处27改为28,增加
aryFileName(28)="/TEMPLATE/b_article_mutuality.html"
aryFileName_Variable(28)="TEMPLATE_ARTICLE_mutuality"
5.c_system_lib.asp
Class TArticle增加一行
Public Template_Article_Mutuality
Public Function Export(intType)增加两行,注意Call Export_Mutuality一定要放在Call Export_Tag的前面,否则会出错。
Call Export_Mutuality
Template_Article_Single=Replace(Template_Article_Single,"<#template:article_mutuality#>",Template_Article_Mutuality)
以下部分找个地方放下就可以了
[CODE_LITE] '相关文章的生成 Function Export_Mutuality() Call CheckParameter(ID,"int",0) If (ID=0) Then Del=False:Exit Function If Tag<>"" Then Dim strCC_Count,strCC_ID,strCC_Name,strCC_Url,strCC_PostTime,strCC_Title Dim strCC Dim i Dim j Dim objTNode Dim objCNode Dim objSingleNode Dim objNodeText Dim objMutArticle Dim objRS Dim strSQL Set objRS=Server.CreateObject("ADODB.Recordset") strSQL="SELECT top 30 [log_ID],[log_Tag],[log_CateID],[log_Title],[log_Level],[log_AuthorID],[log_PostTime],[log_Url] FROM [blog_Article] WHERE ([log_Level]>2) AND [log_ID]<>"& ID &" " Dim aryTAGs If InStr(Tag,"}{") > 0 Then aryTAGs = Split(Tag,"}{") Else ReDim aryTAGs(0) aryTAGs(0) = Tag End If strSQL = strSQL & " AND (" For j = 0 To UBound(aryTAGs) If Not (IsNull(aryTAGs(j)) Or IsEmpty(aryTAGs(j)) Or aryTAGs(j) = "" Or Len(aryTAGs(j)) < 1) Then aryTAGs(j) = Replace(Replace(aryTAGs(j),"}",""),"{","") If IsNumeric(aryTAGs(j)) Then If j > 0 Then strSQL = strSQL & " OR " strSQL = strSQL & "([log_Tag] Like '%{"&aryTAGs(j)&"}%')" End If End If Next strSQL = strSQL & ")" strSQL = strSQL + " ORDER BY [log_PostTime] DESC " Set objRS=Server.CreateObject("ADODB.Recordset") objRS.CursorType = adOpenKeyset objRS.LockType = adLockReadOnly objRS.ActiveConnection=objConn objRS.Source=strSQL objRS.Open() If (not objRS.bof) And (not objRS.eof) Then For i=1 To 30 '相关文章数目,可自行设定 strCC_Count=strCC_Count+1 strCC_ID=objRS("log_ID") strCC_Url=objRS("log_Url") strCC_PostTime=objRS("log_PostTime") strCC_Title=objRS("log_Title") Application.Lock strCC=Application(ZC_BLOG_CLSID & "TEMPLATE_ARTICLE_Mutuality") Application.UnLock If IsNull(strCC_Url) Or IsEmpty(strCC_Url) Or strCC_Url="" Then strCC_Url=strCC_ID end if strCC=Replace(strCC,"<#article/mutuality/id#>",strCC_ID) strCC=Replace(strCC,"<#article/mutuality/url#>",strCC_Url) strCC=Replace(strCC,"<#article/mutuality/posttime#>",strCC_PostTime) strCC=Replace(strCC,"<#article/mutuality/name#>",strCC_Title) Template_Article_Mutuality=Template_Article_Mutuality & strCC objRS.MoveNext If objRS.eof Then Exit For Next End if objRS.Close() Set objRS=Nothing End If Export_Mutuality=True End Function[/CODE_LITE]