之前有試過把相關文章顯示在文章底下,可是都不成功。今天看了小雪的留言后,再去google搜尋了一下,終于找到了一個可以成功顯示的方法。
How to Show Related Posts / Articles in Blogspot Blogs - Create Related Posts Plugin / Widget for Blogger 是由Debajyoti Das 參考了 Mohamed Rias 的方法改良而成的。
方法雖然簡單,只有兩個步驟,可是內里的程式碼卻要花很多心思才能完成的,我們應該感謝 Debajyoti Das 及 Mohamed Rias 的貢獻。
步驟1
登錄你的blogger,點按『layout』-》『edit html』-『expand widget templates』。
點按『ctrl+f』,輸入『/head』搜尋下列程式碼。
</head>
把下列程式碼復制到</head>的上一行。
<style>
#related-posts {
float : left;
width : 540px;
margin-top:20px;
margin-left : 5px;
margin-bottom:20px;
font : 11px Verdana;
margin-bottom:10px;
}
#related-posts .widget {
list-style-type : none;
margin : 5px 0 5px 0;
padding : 0;
}
#related-posts .widget h2, #related-posts h2 {
color : #940f04;
font-size : 20px;
font-weight : normal;
margin : 5px 7px 0;
padding : 0 0 5px;
}
#related-posts a {
color : #054474;
font-size : 11px;
text-decoration : none;
}
#related-posts a:hover {
color : #054474;
text-decoration : none;
}
#related-posts ul {
border : medium none;
margin : 10px;
padding : 0;
}
#related-posts ul li {
display : block;
background : url("http://i299.photobucket.com/albums/mm297/zozuglogger/weed-bullet.gif") no-repeat 0 0;
margin : 0;
padding-top : 0;
padding-right : 0;
padding-bottom : 1px;
padding-left : 16px;
margin-bottom : 5px;
line-height : 2em;
border-bottom:1px dotted #cccccc;
}
</style>
<script src='http://technotrixdebajyoti.googlepages.com/RelatedPostsByRealtrix.co.cc.js' type='text/javascript'/>
步驟2
把下列程式碼復制到<p><data:post.body/></p>的下一行
<b:if cond='data:blog.pageType == "item"'>
<div id="related-posts">
<font face='Arial' size='3'><b>Related Posts : </b></font><font color='#FFFFFF'><b:loop values='data:post.labels' var='label'><data:label.name/><b:if cond='data:label.isLast != "true"'>,</b:if><b:if cond='data:blog.pageType == "item"'>
<script expr:src='"/feeds/posts/default/-/" + data:label.name + "?alt=json-in-script&callback=related_results_labels&max-results=5"' type='text/javascript'/></b:if></b:loop> </font>
<script type='text/javascript'> removeRelatedDuplicates(); printRelatedLabels();
</script>
</div></b:if>