Archived Post: Tab View

Dear Friend,

Now that I have the new framework for making widgets in store, I feel confident and start trying to create a new tab widget - using labels as tabs, similar to this Yahoo! widget.

With the wonderful help of Yahoo! TabView widget, the programming time reduces quite a bit.

You can see the result from my homepage:

If you want to install this onto your blog, follow these instructions.

Step 1: Installing the core Javacript library object

First, follow the instructions from this article Hacking Technique: How To Modify a (Beta) Template, in particular section C.2 (for step 1 & 2) and B.4 (for step 3).

Next, install the latest version of the Javacsript Core Library.

Save the template.

Step 2: Installing Yahoo! Tab View requirements

Cut and paste this code below right after step 1's code (such that these code still stay before the closing </head> tag.). See instruction here if you're still not sure.

<link href='' rel='stylesheet' type='text/css'/>

<link href='' rel='stylesheet' type='text/css'/>

<script src='' type='text/javascript'/>
<script src='' type='text/javascript'/>

<script src='' type='text/javascript'/>

<style type='text/css'>

.yui-content {
padding:1em; /* pad content container */

.yui-navset .yui-content {
border:1px solid #ccc;
.yui-navset .yui-nav .selected a, .yui-navset .yui-nav a:hover {

.yui-navset .yui-nav li a {
background:#e5e5e5 url( no-repeat;
.yui-navset .yui-nav li a em {
background:transparent url( no-repeat top right;

/* top oriented */

.yui-navset-top .yui-nav { margin-bottom:-1px; } /* for overlap, based on content border-width */
.yui-navset-top .yui-nav li a {
border-bottom:1px solid #ccc;

.yui-navset-top .yui-nav .selected a { border-bottom:0; }
.yui-navset-top .yui-nav .selected a em { padding-bottom:0.6em; } /* adjust height */

Save the template.

Step 3: Installing the widget

Add this code between any two "b:widget" tags, save the template, and you're almost done.

<b:widget id='HTML102' locked='false' title='MultiTab Widget' type='HTML'>
<b:includable id='main'>
<div class='widget-content'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'
<div id='doc'>
<h2>Hoctro's Place</h2>
<div class='yui-navset' id='multiTab1'/>

<div class='yui-navset' id='multiTab2'/>

<div id='103'/>

<script type='text/javascript'>
// Developed by Hoctro - All rights reserved 2007
// This credit must be included in all your derived usages.
var p1 = document.createElement('h6');
p1.innerHTML = cb.txt('TabView');

function listOneTab(json, tabView, title, act) {
var label = '';
var text = '';
var nPost = 10;

if (title == "")
label += cb.getLabelFromURL(json);
label += title;

text += "<div id='" + label + "'><ul>";

var numberPost = (json.feed.entry.length &lt;= nPost) ?
json.feed.entry.length : nPost;

for (var i = 0; i &lt; numberPost; i++) {
var entry = json.feed.entry[i];
text += "<li>" + "&lt;a href='" + cb.getLink(entry, "alternate")
+ "'&gt;" + cb.getTitle(entry) + "</li>";

text += '</ul></div>';

tabView.addTab( new YAHOO.widget.Tab({
label: label,
content: text,
active : act


var blog1 = "";
var tabView1 = new YAHOO.widget.TabView('multiTab1');
var labels1 = ['JSON Hacks', 'Label Hacks','Free Templates'];
function listTab1(json) {
listOneTab(json, tabView1, "", false);
function listLatestPostsTab1(json) {
listOneTab(json, tabView1, "Latest Posts", true);
function listLatestCommentsTab1(json) {
listOneTab(json, tabView1, "Latest Comments", false);

// Activating calls!

// Latest Posts blog1, "posts", 1, 25, 'listLatestPostsTab1');

// Latest Comments blog1, "comments", 1, 25, 'listLatestCommentsTab1');

// Preferred Labels
for (var i=0; i &lt; labels1.length; i++)
if (labels1[i]) cb.searchLabel(blog1, labels1[i], 'listTab1');

var blog2 = "";
var tabView2 = new YAHOO.widget.TabView('multiTab2');
var labels2 = ['Neo','Widgets', "Blogger Power"];
function listTab2(json) {
listOneTab(json, tabView2, "", false);
function listLatestPostsTab2(json) {
listOneTab(json, tabView2, "Latest Posts", true);
function listLatestCommentsTab2(json) {
listOneTab(json, tabView2, "Latest Comments", false);
// Activating calls!
// Latest Posts blog2, "posts", 1, 25, 'listLatestPostsTab2');

// Latest Comments blog2, "comments", 1, 25, 'listLatestCommentsTab2');

// Preferred Labels
for (var i=0; i &lt; labels2.length; i++)
if (labels2[i]) cb.searchLabel("", labels2[i], 'listTab2');


Save the template.

After you install the above three easy steps, just change these things found in step 3' code:

a. To change the title, look for this line:

<h2>Hoctro's Place</h2>

b. modify the label tabs to become yours:

var labels1 = ["JSON Hacks", "Label Hacks",
"Free Templates", "Notable Hacks"

c. Change value below from 10 to any value you want for the maximum of posts per tab

var nPost = 10;

d. then replace mine with your blog's name

blog1 = "";

For advanced bloggers who would like to manipulate the CSS, "step 2" contains the information to do so. Also consult the Yahoo! TabView widget tutorials and examples for other variations of these tab options.

To add another tabview to this widget such as the picture below, please see part 2.

Until next time.

* 24 May 07: A translation of this article to Indonesian by Bikin is available here:

*26 May 07: Wai Yan Lin translated also part 1, 2 & fav blogs application to Burmese here: