
What is Sliding doors?
Sliding doors CSS hack had been around for a long while. As this tutorial will walk you through how to add this hack to your site. The reason to add this quick and easy hack is because WordPress core functions wp_list_pages() and wp_list_categories() doesn’t support the function to add a span tag in this css menu. This hack is to insert the extra span which needed to create the menu.
Task needed to complete.
- Inserting PHP code to your header.php file
- Inserting the CSS to your style sheet
The Sliding doors top navigation hack for WordPress.
This is a strict hack to enhance the wp_list_pages() or wp_list_categories(), NO CHANGE OF CORE. Since wordpress update there security issue quite frequently, it is not ideal to change the core file period. In the below php code we will be using a regular expression of php preg_replace().
To create the menu we are going to use, let’s paste in the below code for your pages or categories in your header.php WordPress theme.
php code
To list your Pages:
<div id="dsnav" class="clearfix">
<ul id="cssmenu">
<li><a href="<?php echo get_option('home'); ?>/"><span>Home</span></a></li>
<?php echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a$2><span>$3</span></a>', wp_list_pages('echo=0&orderby=name&exlude=181&title_li=&depth=1')); ?>
</ul>
</div>
php code
To list your Categoreis:
<div id="dsnav" class="clearfix">
<ul id="cssmenu">
<li><a href="<?php echo get_option('home'); ?>/"><span>Home</span></a></li>
<?php echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i', '<li$1><a$2><span>$3</span></a>', wp_list_categories('echo=0&orderby=name&exlude=181&title_li=&depth=1')); ?>
</ul>
</div>
After the code
After the code had successfully been inserted to your code, you should have something similar to the image below.

But now you will be saying, this is a bit ugly, I want something similar to your site or other website. So now we will need to include some css to get rid of the bullets and styling it like a menu. Let’s now take a look at the menu structure from the source code.
css style
For the one who doesn’t want to know the details of the css, who just want the code, here’s the whole chunk.
#dsnav {
float:left;
overflow:visible;
padding:0;
position:relative;
width:100%;
background:#999;
}
#cssmenu ul {
margin: 0; /* all lists */
padding: 0;
}
#cssmenu {
height:30px;
margin:0;
overflow:hidden;
padding:0 20px;
}
#cssmenu li {
display:block;
float:left;
margin:4px 10px 0 0;
padding:0;
}
#cssmenu li a {
background:#CCC;
-moz-border-radius:5px;
-webkit-border-radius: 5px;
color:#000000;
display:block;
font-size:80%;
font-weight:normal;
padding:4px 6px;
text-decoration:none;
text-transform:uppercase;
}
li.current-cat a{
background:#000!important;
color:#FFF!important;
}
#cssmenu li a:hover {
background:#000;
color:#FFF
}
li.current-cat a:hover{
background:#333!important;
color:#ccc!important;
}
css style explanation
#dsnav id tag simply just added a 100% background to the back of your menu. This is basically the very bottom layer for your menu.
#dsnav {
float:left;
padding:0;
margin:0;
width:100%;
background:#999;
}
.clearfix{
clear:both;
}
#cssmenu li {
display:block;
float:left;
margin:4px 10px 0 0;
padding:0;
text-transform:uppercase;
}
- Add a background color
- Add the round corner for firefox and sarafi, IE are just not welcome for this class(sorry for the IE lover)
- Control the text color
- Display it in block, so this will clear off the spacing problem
- Create the font size, weight
- Add padding to your a tag so it is more roomy inside.
#cssmenu li a {
background:#CCC;
-moz-border-radius:5px;
-webkit-border-radius: 5px;
color:#000000;
display:block;
font-size:0.8em;
font-weight:normal;
text-decoration:none;
padding:4px 6px;
}
After the code you will have something similar to this.

#cssmenu li {
display:block;
float:left;
margin:4px 10px 0 0;
padding:0;
text-transform:uppercase;
}
#cssmenu ul {
margin: 0; /* all lists */
padding: 0;
}
#cssmenu {
height:30px;
margin:0;
overflow:hidden;
padding:0 20px;
}

You should have some breathing space to your menu now.
li.current-cat a{
background:#000!important;
color:#FFF!important;
}
#cssmenu li a:hover {
background:#000;
color:#FFF
}
li.current-cat a:hover{
background:#333!important;
color:#ccc!important;
}

Now you have the basic knowledge of css, do play around with your style. If you have any problem with css, please leave us a comment.
I hope you have enjoyed this post, be sure to subscribe to my rss feed by click the subscribe button at the top.
Good Luck!



Simply want to say your article is stunning. The lucidity in your post is simply impressive and i can assume you are an expert on this subject. Well with your permission allow me to grab your rss feed to keep up to date with incoming post. Thanks a million and please keep up the effective work.
While doing research for adding rss to blog on Sunday your post regarding Adding a top navigation on wordpress | Designer Sandbox came up. Just wanted to drop a note to let you know what a great site you have. It is a great resource and a great place to drop by.
Thank u . It is awesome
Great info! Thanks very much! Will give it a shot.