Blogging is not rocket science, it’s about being yourself, and putting what you have into it. — Unknown

How to Add MooTabs to Your WordPress Theme

It seems like adding tabs to display a variety of WordPress lists in the sidebar is getting very popular. It saves space and allows us to display a lot of content, not to mention, it looks kind of neat too.

Installing MooTabs is the easiest part. Styling it is the hardest part. The default template looks very ugly. Although I won’t go into great detail on how to style it, I will point out certain installation tips for WordPress sites that will improve the performance of your WordPress sites.

Step 1: Download MooTabs

Go to MooTabs’ web site to download the latest version of MooTabs. At the time of this writing the latest version is 1.2. You will also need to download MooTools. The latest version of MooTools is 1.2.1 but it does not work with MooTabs 1.2! I could not find MooTools 1.11 on MooTools’ web site.

I uploaded MooTools 1.11 to my web server. If you can’t find it anywhere on the internet, download MooTools 1.11 from us instead.

Step 2: Upload MooTabs to Your WordPress Theme’s Folder

I like to store my Javascript files in a folder called “js”. For my CSS files, I like to store them in a folder called “css”. Let’s assume my template folder is called “cooltemplate”, you should upload the MooTabs files in the following manner:

1. /wp-content/themes/cooltemplate/css – Upload mootabs1.2.css here.
2. /wp-content/themes/cooltemplate/js – Upload mootabs1.2.js and mootools.v1.11.js here.

Step 3: Add MooTabs References to Your WordPress Theme’s header.php

Add the following code to your theme’s header.php file in between the head tags.

1
2
3
4
5
6
7
8
9
10
11
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo bloginfo('template_directory'); ?>/css/mootabs1.2.css" />
<script type="text/javascript" src="<?php echo bloginfo('template_directory'); ?>/js/mootools.v1.11.js"></script>
<script type="text/javascript" src="<?php echo bloginfo('template_directory'); ?>/js/mootabs1.2.js">
</script>
<script type="text/javascript">
window.addEvent('domready', init);
function init()
{
	myTabs_object = new mootabs('myTabs', {height: 'auto', width: 'XXXpx', changeTransition: 'none', mouseOverClass: 'over'});
}
</script>

If you only display MooTabs on the blog pages, do this to prevent the loading of the MooTabs files on non-blog pages.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
if(!is_page())
{
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo bloginfo('template_directory'); ?>/css/mootabs1.2.css" />
<script type="text/javascript" src="<?php echo bloginfo('template_directory'); ?>/js/mootools.v1.11.js"></script>
<script type="text/javascript" src="<?php echo bloginfo('template_directory'); ?>/js/mootabs1.2.js"></script>
<script type="text/javascript">
window.addEvent('domready', init);
function init()
{
	myTabs_object = new mootabs('myTabs', {height: 'auto', width: 'XXXpx', changeTransition: 'none', mouseOverClass: 'over'});
}
</script>
}
?>

It does not matter what you write for the code “MyTabs_object”. However, the code “myTabs” must match the HTML code you use in the sidebar. Feel free to change “XXXpx” to your desired width. e.g. 250px.

An alternative way to initialize the MooTabs would be to save the following code into a Javascript (.js) file.

1
2
3
4
5
6
7
<script type="text/javascript">
window.addEvent('domready', init);
function init()
{
	myTabs_object = new mootabs('myTabs', {height: 'auto', width: 'XXXpx', changeTransition: 'none', mouseOverClass: 'over'});
}
</script>

Step 4: Add MooTabs Code into Your WordPress Theme’s sidebar.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<div id="myTabs">
	<ul>
		<li title="Tab1">Tab 1 Label</li>
		<li title="Tab2">Tab 2 Label</li>
		<li title="Tab3">Tab 3 Label</li>
	</ul>
 
	<div id="Tab1">
	</div>
 
	<div id="Tab2">
	</div>
 
	<div id="Tab3">
	</div>
</div>

This is the default code of the MooTabs. You may update “Tab 1 Label” to anything you want. The code “Tab1″ in the “li title” must match with the “div id” code below it or it won’t work. In the previous step, I have configured my MooTabs to have “auto” height so that the content I insert in the tabs will automatically stretch the height of the MooTabs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<div id="post_tabs">
	<!-- MOO TAB TITLES - START -->
	<ul class="post_tabs_title">
		<li title="Latest">Latest</li>
		<li title="Popular">Popular</li>
		<li title="Comments">Most Comments</li>
	</ul>
	<!-- MOO TAB TITLES - END -->
 
	<!-- LATEST POSTS - START -->
	<div id="Latest" class="mootabs_panel">
		<?php if(function_exists('recent_posts')) { recent_posts(); } ?>
	</div>
	<!-- LATEST POSTS - END -->
 
	<!-- POPULAR POSTS - START -->
	<div id="Popular" class="mootabs_panel">
		<?php if(function_exists('popular_posts')) { popular_posts(); } ?>
	</div>
	<!-- POPULAR POSTS - END -->
 
	<!-- MOST COMMENTED POSTS - START -->
	<div id="Comments" class="mootabs_panel">
		<ul><?php if(function_exists('mdv_most_commented')) { mdv_most_commented(10); } ?></ul>
	</div>
	<!-- MOST COMMENTED POSTS - END -->
</div>

The MooTabs is a great place to insert all the comments and post lists. I personally use it to display the recent posts, popular posts, most commented posts, recent comments and top commenters.

Similar Posts

Facebook Comments

6 Comments On “How to Add MooTabs to Your WordPress Theme”

On 21st March 2009 9:09 AM, Rita said:

I did exactly what you described and it doesn’t work. Put the css in the css folder of my theme, the 2 js in the js-folder of my theme, the fist code with width 500 px in the header file, didn’t use the second and third code, put the HTML in the main column, where the mootab should appear. All elements of the Table are shown, but not as a MooTab, just as a list.

So, the HTML-Code seems to be right.

Is the anything missing?

Thanks
Rita

On 21st March 2009 4:22 PM, Vincent said:

I don’t think you did exactly as I described because you left out certain codes. The Javascript code that launches the MooTabs is critical. Please add all code in step 3 and 4.

On 1st April 2009 10:10 AM, Rita said:

Sorry, it still doesn’t work. I now put the js code in an .js named moostart an put this in the js-Folder.

Inserting the 2. Code under 3 in the index page produces an error: Parse error: syntax error, unexpected ‘<’ in …

Sorry, if I seem to be stupid, believe me, I’m not :-(

Rita

On 14th April 2009 2:03 AM, Vincent said:

Try disabling all your WordPress plugins to see if that helps. Then enable them 1 by 1 to make sure no plugins clash with the MooTabs.

I suspect there is a syntax error with your code.

On 3rd May 2009 4:50 PM, Ghazala Khan said:

Hello, following your tutorial, I installed mootabs at my wordpress blog at http://www.pakspectator.com. I am using it to display, top posts and recent comments in tabs. It works fine in FF, but not in IE7.

Would you please be kind enough to take a look in the sidebar of http://www.pakspectator.com and suggest me any solution please?

I will be extremely gratefu.

regards

Ghazala

On 13th September 2009 3:27 PM, N-Designs said:

not working..
‘m using the jquery tabs

3 Trackbacks On “How to Add MooTabs to Your WordPress Theme”

Post a Comment


(Required)


(Required)