给MovableType增加相关文章

| No Comments | No TrackBacks

根据Tag来推荐是很简单的一种,可以参考的几个地方:
http://wiki.movabletype.org/Related_Entries
http://www.jimramsey.net/2008/08/adding-related-entries-to-mid-.html
http://www.devlounge.net/code/related-entries-in-movable-type

基于全文索引的相关性:
http://cxliv.org/2008/07/28/displaying_related_entries_on_your_movable_type_site.php

现在懒得增加插件,所以直接找了方便简单的使用Tag来推荐。

重点使用了devlounge.net的代码,不过之前没仔细看文章,copy过来的时候还特意做了一些代码美化,结果居然没法正常使用:

原来MT的setvarblock有bug,设置标签时这个代码块最好不要自己换行。

原文如下:

It's very important that when you type this in there are no line breaks within any of the <mt:setvarblock></mt:setvarblock> containers. In theory, you should be able to use the strip_linefeeds attribute and not worry about line breaks, but I've not had any luck with that. In fact, it's revealed a very strange bug. Rather than deal with bugs, we'll just remove the line breaks ourselves.

MT的论坛上也有相关反馈:

http://forums.movabletype.org/2008/08/error-when-rebuilding-after-ad.html

最后的代码:

 

<mt:EntryifTagged>
<mt:SetVarblock name="curEntry">
<mt:Entryid />
</mt:SetVarblock>

<mt:SetVarBlock name="taglist"><mt:EntryTags glue=" OR "><mt:TagName></mt:EntryTags></mt:SetVarBlock>

<mt:SetVarblock name="listitems">
<mt:Entries tags="$taglist" unique="1" lastn="6">
<mt:SetVarblock name="listEntry">
<mt:Entryid />
</mt:SetVarblock>

<mt:unless name="listEntry" eq="$curEntry">
<li> <a href="<mt:Entrypermalink />"><mt:Entrytitle /></a></li>
</mt:unless>
</mt:entries>
</mt:SetVarblock>

<mt:if name="listitems">
<div>
<h3>Related Entries</h3>
<ul>
<mt:Var name="listitems">
</ul>
</div>
</mt:if>
</mt:EntryifTagged>

 

--EOF--

No TrackBacks

TrackBack URL: http://www.guduo.net/cgi-bin/mt/mt-tb.cgi/171

Leave a comment

Pages

May 2016

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

About this Entry

This page contains a single entry by 谷多 published on March 22, 2009 3:26 PM.

MovableType的很不爽的一个地方:模板集合替换的问题 was the previous entry in this blog.

恢复和修改了RSS2.0的模板 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.