给MovableType增加相关文章

| 1 Comment | 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

1 Comment

你这个BLOG要留言很麻烦啊。

请问我的相关文章为什么会包含自己的文章呢??

就是说:
自己页面是:A
相关文章显示:A,B,C...
如何让A不显示呢?

我复制过你帖的代码过去,也是一样的,但你的相关文章却没有显示自己,怎么回事呢?

谢谢诶!

我的代码如下:
http://blog.freebapp.org/2009/05/movable-type-1.html

Leave a comment

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.