UTW本身是一个强大的tag工具,同时它也内置了根据文章本身的tag提供相关文章的功能。使用这个功能,就无需其他另外的关键字作为索引来构建相关文章,具有相同tag的文章无疑就已经是相关的了。
实现方法也很简单,为利用了UTW提供的一个UTW_ShowRelatedPostsForCurrentPost函数,只要在恰当的位置加上这个函数,就会输出相关文章。
我写了一个relatedentries.php的文件,内容如下:
<?php if ((function_exists(’UTW_ShowRelatedPostsForCurrentPost’)) && is_single() && ($notfound != ‘1′)) { ?>
<div class=”related_entries”><h5>Related Entries</h5>
<ul>
<?php UTW_ShowRelatedPostsForCurrentPost(”posthtmllist”, ”, 10); ?>
</ul>
</div>
<?php } ?>
然后要做的就是在恰当的位置包含这个文件了,由于我使用的是K2的模板,因此我需要修改的是/wp-contents/themes/k2/single.php。将上面的文件放在与single.php相同的目录,然后修改single.php。具体修改的地方是在如下代码行以下再插入一句代码:
<?php include (TEMPLATEPATH . ‘/theloop.php’); ?>
要插入的代码为:
<?php include (TEMPLATEPATH . ‘/relatedentries.php’);?>
至此修改就完成了,效果见本Blog文章的相关文章。
文章分类
- Cartoon and Anime (12)
- FreeBSD (12)
- Game (3)
- Hardware (12)
- IT (3)
- Joke (15)
- Life goes on (55)
- Linux (14)
- Music (9)
- Networking (35)
- Programming (4)
- Software (17)
- solaris (2)
- tips (1)
- Weblog (41)
- Windows (22)
按月归档
- May 2008 (3)
- April 2008 (3)
- March 2008 (3)
- February 2008 (3)
- January 2008 (2)
- December 2007 (3)
- November 2007 (10)
- October 2007 (12)
- September 2007 (8)
- August 2007 (7)
- July 2007 (10)
- June 2007 (12)
- May 2007 (14)
- April 2007 (14)
- March 2007 (18)
- February 2007 (11)
- January 2007 (8)
- December 2006 (12)
- November 2006 (13)
- October 2006 (5)
- September 2006 (9)
- August 2006 (13)
- July 2006 (13)
- June 2006 (16)
- May 2006 (21)
Weblog







