Join over 55,891 Subscribers Today! FREE UPDATES!
Get The Only Freelancer crash course you will ever need to read!
Tired of the boring category style being always same, like a mini menu? Tired of items arranged horizontally or vertically, styled always the same way? Yes, I’m tired of it too. So let’s make things more interesting now.
Our starting point will be a cool sliding tags design made by Thomas Bosée. Then we’ll learn how to use WordPress wp_list_categories function, how to edit its result, how to code CSS and finally a little of jQuery “Black Magic”.
So, let’s rock!
So our goal is to achieve the effect seen on this demo. As usual you can download our sample files and edit as you want!

Wp_list_categories is a function that gets all categories and has a few useful parameters. We’ll be using a few of them:
Our php will be like this:
<ul> <?php $args = array ( 'echo' => 0, 'show_count' => 1, 'title_li' => '', 'depth' => 1 ); $variable = wp_list_categories($args); echo $variable; ?> </ul>
And this PHP outputs this HTML:
<ul id="category"> <li class="cat-item cat-item-8"><a href="#design">design</a> (17)</li> <li class="cat-item cat-item-6"><a href="#icon">icon</a> (9)</li> <li class="cat-item cat-item-7"><a href="#grid">grid</a> (3)</li> <li class="cat-item cat-item-9"><a href="#clean">clean</a> (25)</li> <li class="cat-item cat-item-1"><a href="#typography">typography</a> (8)</li> <li class="cat-item cat-item-5"><a href="#minimal">minimal</a> (12)</li> <li class="cat-item cat-item-5"><a href="#illustration">illustration</a> (1)</li> <li class="cat-item cat-item-5"><a href="#high-resolution">high resolution</a> (6)</li> <li class="cat-item cat-item-5"><a href="#iphone">iphone</a> (15)</li> <li class="cat-item cat-item-5"><a href="#interface">interface</a> (21)</li> <li class="cat-item cat-item-5"><a href="#grunge">grunge</a> (10)</li> </ul>
As you may notice, the default post count is simple text with parenthesis. Well, in our original design we have count as a separate element, so we’ll need to change this default behavior. A simple way of doing this is with str_replace, we’ll search for “(“, replace with “<span>” and then search for “)” e replace with “</span>”.
This is how your category listing function will be:
<ul>
<?php
$args = array (
'echo' => 0,
'show_count' => 1,
'title_li' => '',
'depth' => 1
);
$variable = wp_list_categories($args);
$variable = str_replace ( "(" , "<span>", $variable );
$variable = str_replace ( ")" , "</span>", $variable );
echo $variable;
?>
</ul>
And now we’ll have right HTML, as follows:
<ul id="category"> <li class="cat-item cat-item-8"><a href="#design">design</a> <span>17</span></li> <li class="cat-item cat-item-6"><a href="#icon">icon</a> <span>9</span></li> <li class="cat-item cat-item-7"><a href="#grid">grid</a> <span>3</span></li> <li class="cat-item cat-item-9"><a href="#clean">clean</a> <span>25</span></li> <li class="cat-item cat-item-1"><a href="#typography">typography</a> <span>8</span></li> <li class="cat-item cat-item-5"><a href="#minimal">minimal</a> <span>12</span></li> <li class="cat-item cat-item-5"><a href="#illustration">illustration</a> <span>1</span></li> <li class="cat-item cat-item-5"><a href="#high-resolution">high resolution</a> <span>6</span></li> <li class="cat-item cat-item-5"><a href="#iphone">iphone</a> <span>15</span></li> <li class="cat-item cat-item-5"><a href="#interface">interface</a> <span>21</span></li> <li class="cat-item cat-item-5"><a href="#grunge">grunge</a> <span>10</span></li> </ul>
(A.K.A. CSS3. Yeah, a really bad joke)
Now we’ll do this with a few cool CSS3 implementations. This is what will help us:
Let’s go step by step. Basic CSS for background and main div positioning. Nothing really major in here:
body {
background: url(bg.png);
}
#container {
position: relative;
width: 500px;
margin: 50px auto 0;
padding: 10px 0 20px;
}
With #category and li rules we’ll achieve that side-by-side listing.
#category {
margin: 0;
padding: 0;
list-style-type: none;
overflow: hidden;
}
#category li {
float: left;
position: relative;
padding: 0 10px;
margin: 0 15px 10px 0;
}
Our link styling will create that “white” part of our little tag. Background is a 1px wide soft gradient:
#category li a {
float: left;
padding: 4px 10px 0;
height: 18px;
font-family: "arial";
font-size: 10px;
color: #3f3f3f;
text-decoration: none;
border-top: 1px solid #d3d0cf;
border-left: 1px solid #cac7c7;
border-bottom: 1px solid #aeadad;
background: url(bgTag.png) repeat-x;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
}
Now we need to create the orange part of our tag. Since we’ll animate just the “middle”, we’ll have to do it in a way that our before and after elements will be “inside” of span but will go to right / left as our main element expands. So this will do the trick:
#category li span {
position: relative;
float: left;
width: 35px;
padding: 5px 0 0;
margin-top: 1px;
height: 18px;
font-family: "arial";
font-size: 10px;
color: #3f3f3f;
text-align: center;
background: url(bgCount.png);
overflow: hidden;
}
#category li span:before, #category li span:after {
position: absolute;
top: 0;
left: 0;
width: 3px;
height: 30px;
content: url(bgBeforeCount.png);
overflow: hidden;
}
#category li span:after {
left: auto;
right: 0;
content: url(bgAfterCount.png);
}
First of all, we need to include jQuery, right? So we’ll do it with a really cool technique that I’ve seen at jQuery boilerplate:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js" type="text/javascript"></script>
<script type="text/javascript">window.jQuery || document.write("\x3Cscript src='js/jquery-1.7.1.min.js' type='text/javascript'>\x3C/script>")</script>
We’ll try to get it from Google. Since almost everybody visits Google often we have a good chance of getting this right from the users cache. But if for any crazy reason Google is down (for instance, if we have been hit by a giant meteor just like our dino friends) it’ll get jQuery from our local file :)
Now we need to show / hide post counts when hovering over them, so our basic logic will be:
FIND all "#category span" tags
animate their width to 0px
FIND all "#category li" tags
WHEN mouseenter
animate this.children("span") width to 35px
WHEN mouseleave
animate this.children("span") width to 0px
When translating this to jQuery what you need to be aware of is:
Our final jQuery code will be this crazy thing:
$(function(){
$("#category")
.find("span")
.each(function(){
$(this).animate({"width": "5px"});
})
.parent()
.hover(
function(){
$(this).find("span").stop().animate({"width": "35px"});
}, function() {
$(this).find("span").stop().animate({"width": "5px"});
}
);
});
Hope you enjoyed reading. Don’t be shy and share your thoughts with us!
Get The Only Freelancer crash course you will ever need to read!
I'm a web designer and entrepreneur from Itajubá (MG), Brasil. I love writing about obscure topics and doing some cool stuff. And also I do some FREE stuff, check it out: http://www.roch.com.br/
Sunday, January 15th, 2012 00:46
Hey Rochester,
I love this elegant tag script you have, and I would to have this on my website,
but please can you give me step by step guide how to do this?
I mean, I downloaded all the files, but when I put the “wordpress-sliding-category” map in the plugins folder
the “elegant tag” plugin does not appear in my wp-admin plugin section.
I want this elegant tags in the bottom of my page, now I know how to create and edit things, and create widget etc
but which code do I have to implement? and where do I have to upload this “wordpress-sliding-category” folder?
Thanks in advice,
Great blog you have,
PS, sry for my poor English ;)
Best regards,
AJ
Sunday, January 8th, 2012 20:02
loved it, appreciate your work mate.
Monday, January 2nd, 2012 08:22
Thanks very mutch for this useful article
Wednesday, December 28th, 2011 11:38
Why not click on the demo and download Where can I download?
Tuesday, December 27th, 2011 14:13
I really love the sliding effect. I wonder if this technique can also be applied to WordPress Tag?
Going to bookmark it for future usage ;) Thanks!
Friday, December 16th, 2011 12:35
Love that JQuery pikie, going to use that from now on! Nice effect on the tags.
If not, then it's time to learn how to:
You can trust 1stWebDesigner to help you become a better web designer!
- Jacob Cass | Just Creative
Just enter your name and email below and click Get Updates!
Angus Pearson
Friday, December 16th, 2011 12:35
Love that JQuery pikie, going to use that from now on! Nice effect on the tags.
Rochester Oliveira
Monday, January 2nd, 2012 19:02
Thanks Angus :)
I’m glad you liked it, and hope to see you again soon!
[]‘s
Jaafar
Monday, January 2nd, 2012 08:22
Thanks very mutch for this useful article
Rochester Oliveira
Monday, January 9th, 2012 03:59
Hi Jaafar,
I’m glad you liked!
Keep coming, we’ve much more like this to go!
[]‘s
Audee
Tuesday, December 27th, 2011 14:13
I really love the sliding effect. I wonder if this technique can also be applied to WordPress Tag?
Going to bookmark it for future usage ;) Thanks!
Rochester Oliveira
Monday, January 2nd, 2012 19:04
Hi Audee,
Yeah, you can do it but it’ll give you a little more work to echo each tag properly, with wp_tag_cloud, for isntance: http://codex.wordpress.org/Function_Reference/wp_tag_cloud
[]‘s
cct
Wednesday, December 28th, 2011 11:38
Why not click on the demo and download Where can I download?
Rean John Uehara
Wednesday, December 28th, 2011 21:00
I’m not sure what you’re asking about, but the demo and download links are there.
Rean John Uehara
Thursday, December 29th, 2011 06:45
Here is for the demo: http://dl.dropbox.com/u/35995890/Slidingtags/index.html
And for the download: http://dl.dropbox.com/u/35995890/Slidingtags/wordpress-sliding-category-FINAL.zip
Nothing is wrong. :/
Rochester Oliveira
Monday, January 2nd, 2012 19:05
Don’t know if it helps, but do you want me to sent it via email?
cct
Saturday, December 31st, 2011 05:45
Haha friends, thank you for such a good thing but I do not download in China
Rochester Oliveira
Wednesday, February 22nd, 2012 22:13
Hi santhosh,
Thanks! We’ll be doing that :)
[]‘s
AJ
Sunday, January 15th, 2012 00:46
Hey Rochester,
I love this elegant tag script you have, and I would to have this on my website,
but please can you give me step by step guide how to do this?
I mean, I downloaded all the files, but when I put the “wordpress-sliding-category” map in the plugins folder
the “elegant tag” plugin does not appear in my wp-admin plugin section.
I want this elegant tags in the bottom of my page, now I know how to create and edit things, and create widget etc
but which code do I have to implement? and where do I have to upload this “wordpress-sliding-category” folder?
Thanks in advice,
Great blog you have,
PS, sry for my poor English ;)
Best regards,
AJ
Rochester Oliveira
Monday, January 16th, 2012 18:35
Hi AJ!
Actually it’s not as a plugin right now, but it is easy to adjust it! Mail me and I’ll help you :) (rochesterj [at] gmail dot com)
[]‘s
tauqueer
Sunday, January 8th, 2012 20:02
loved it, appreciate your work mate.
Rochester Oliveira
Monday, January 9th, 2012 04:00
Hey tauqueer,
Thanks a lot! I’ve worked hard on it actually :)
[]‘s