所以我們只需要把原有的Tag List製做成Tag Cloud即可。
首先,先改CSS的設計部分:
/* Style for Label Cloud */
#labelCloud {
text-align: center;
}
#labelCloud .label-cloud li{
display: inline;
background-image: none !important;
padding: 0 5px;
margin: 0;
vertical-align: baseline !important;
border: 0 !important;
}
#labelCloud ul{
list-style-type: none;
margin: 0 auto;
padding: 0;
}
#labelCloud .label-count {
padding-left: 0.2em;
font-size: 9px;
color: #777;
}
接下來,加入製做Tag Cloud的js code
紅色部分是自訂的地方,諸如blog網址、大小字型、顏色…等。
<!-- User defined inline javascript -->
<script language='javascript' type='text/javascript'>
<!-- Functions used for Label Cloud: adjustLabel(), generateLabels()-->
var labels = new Object;
function adjustLabel(min, max, weight, total) {
if (min > max)
var temp=(min-max)/Math.log(total), result=min-Math.floor(Math.log(weight)*temp);
else
var temp=(max-min)/Math.log(total), result=Math.floor(Math.log(weight)*temp+min);
return result;
}
function generateLabels(){
var blogURL = 'http://abinlee.blogspot.com';
var maxFontSize = 18;
var minFontSize = 11;
var maxColor = [204,204,204];
var minColor = [119,119,119];
var showCount = true;
var labelColor= [];
var labelSize = 0;
var labelCount = new Array();
for (var i in labels)
if (!labelCount[labels[i]])
labelCount[labels[i]] = new Array(labels[i])
total = labelCount.length-1;
section = document.getElementById('labelCloud');
ul = document.createElement('ul');
ul.className = 'label-cloud';
for(var tag in labels) {
for (var i=0; i < 3; i++)
labelColor[i]=adjustLabel(minColor[i], maxColor[i], labels[tag], total);
labelSize = adjustLabel(minFontSize, maxFontSize, labels[tag], total);
li = document.createElement('li');
li.style.fontSize = labelSize+'px';
a = document.createElement('a');
a.title = labels[tag]+' articles with Label: '+tag;
a.style.color = 'rgb('+labelColor[0]+','+labelColor[1]+','+labelColor[2]+')';
a.href = blogURL+'/search/label/'+encodeURIComponent(tag);
if (showCount) {
span = document.createElement('span');
span.innerHTML = '('+labels[tag]+') ';
span.className = 'label-count';
a.appendChild(document.createTextNode(tag));
li.appendChild(a);
li.appendChild(span);
}
else {
a.appendChild(document.createTextNode(tag));
li.appendChild(a);
}
ul.appendChild(li);
ul.appendChild(document.createTextNode(' '));
}
section.appendChild(ul);
}
</script>
最後把widget code展開,找到id='Label1'的widget,將這整個widget以下面的code取代掉。
<b:widget id='Label1' locked='false' title='Labels' type='Label'>
<b:includable id='main'> <!-- Add Label Cloud -->
<b:if cond='data:title'>
<h2><data:title/></h2>
</b:if>
<div class='widget-content'>
<div id='labelCloud'/>
<script type='text/javascript'>
<b:loop values='data:labels' var='label'>
labels["<data:label.name/>"] = <data:label.count/>;
</b:loop>
generateLabels();
</script>
<noscript>
<ul>
<b:loop values='data:labels' var='label'>
<li>
<b:if cond='data:blog.url == data:label.url'>
<data:label.name/>
<b:else/>
<a expr:href='data:label.url'><data:label.name/></a>
</b:if>
(<data:label.count/>)
</li>
</b:loop>
</ul>
</noscript>
<b:include name='quickedit'/>
</div>
</b:includable>
</b:widget>
ps. 因為這樣子做出的Tag Cloud是以Blogger給定的Tag list製做的,所以排序就是以Blogger的設定為主,以次數或是字母排序。當然,改成了Tag Cloud之後,還使用次數排序,就看不出效果啦~