Yes, drop-up is a bit of an oxymoron. Technically you pull something up and drop something down, but since we talk about drop-downs so much, and the effect of what I’m about to show you happens with the same amount of “gravity”, and I’m not an language pedant (all of the time)… it’s okay.
I was asked how one might create a menu to go in the footer and I thought, hey why not show my blog a bit of love? So, what I’m going to do here is make a drop-up menu listing archives, categories and recent posts, using built in WordPress template tags and Thesis menu classes.
This has been tested in Safari and Firefox on Mac and IE6, IE7 and IE8 on Windows. There may be some z-index issues for sub-sub-menus in IE7 and IE8, sub-sub-menus don’t really work at all in IE6 because they’re not wrapped with tables, and position of the drop-up was not perfect in IE6. I wasn’t able to solve these issues. In many cases these bugs might not be visible at all (e.g., if you don’t have any sub-sub-menus), or acceptable sacrifices if you don’t care much about IE6, which I don’t.
The lovely thing about menus in Thesis 1.6 is that all the hard work of CSS dropdowns are done for you, and since the navigation has a class of “menu” (rather than an ID of “tabs”), it’s perfectly okay to reuse this class elsewhere.
The menu code
This code needs to go in custom_functions.php (which is now conveniently accessible via the built in ‘Custom File Editor’).
function custom_footer_nav() {
?>
<ul id="footer_nav" class="menu">
<li><a href="">Archives<!--[if IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="submenu">
<?php wp_get_archives(); ?>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<li><a href="">Categories<!--[if IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="submenu">
<?php wp_list_categories('title_li='); ?>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<li><a href="">Recent Posts<!--[if IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="submenu">
<?php wp_get_archives('type=postbypost&limit=5'); ?>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
</ul>
<?php
}
add_action('thesis_hook_after_footer','custom_footer_nav');
What the code does
The code is wrapped in a PHP function so that we may insert it below the footer using the thesis_hook_after_footer hook.
The HTML that builds the menu is an unordered list, with each list item containing another unordered list. Each sub-list is populated with list items from the template tags wp_get_archives and wp_list_categories, which retrieve links to archives (monthly, daily, post by post, whatever you specify) and categories and present them as list items.
It’s essential that the first unordered list have class="menu" so that it inherits all the built-in dropdown function of the Thesis navigation menu.
Before and after each sub-list is
<!--[if IE 7]><!--></a><!--<![endif]--> <!--[if lte IE 6]><table><tr><td><![endif]-->
and
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
Those are there to tell Internet Explorer not to finish the parent link before the sub-list (because IE6 only allows the :hover selector on links) and for IE6 to wrap the sub-list in a table (for positioning).
A bit of javascript for positioning
The above code will give a functional dropdown menu, but we were after a drop-up menu. To achieve that we need to position the submenus above the parent links by the same number of pixels as their height. This is not currently possible in CSS for dynamic elements (with automatically created height). You could give them a fixed height, but I’m going to use a bit of jQuery to detect the height and then position the submenu.
This should also go in custom_functions.php
if ( !is_admin() ) {
wp_deregister_script('jquery');
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"), false, '1.3.2');
wp_enqueue_script('jquery');
}
function add_to_head() {
?>
<script type="text/javascript">
$(function() {
$("#footer_nav ul.submenu").each(function() {
var listHeight = $(this).height();
$(this).css("top", "-" + listHeight + "px");
});
$("#footer_nav > li").click(function() {
return false;
});
});
</script>
<?php
}
add_action('wp_head','add_to_head');
What the javascript does
The first bit with deregister, register and enqueue script adds a Google hosted jQuery library to the pages on your blog (but not the admin pages in the dashboard).
The function add_to_head() adds some jQuery to the head of your site. It finds the submenu in our footer navigation (#footer_nav ul.submenu) and detects its height in pixels ($(this).height()) then applies CSS of top:-height; so that the submenu is positioned by its full height above the menu.
$("#footer_nav > li").click(function() {
return false;
});
That just makes sure that nothing happens when you click on the top-level links of the footer menu because in this example they don’t go anywhere. You can remove this if you intended to link the top links to real pages.
A bit of CSS to wrap up
This goes in custom.css. All it does is rearrange some of the borders and margins that makes the dropdown navigation lists line up properly, so our drop-up lists line up better. If you have navigation borders set to 0 in the Design Options, you probably don’t need this CSS at all.
.custom #footer_nav {border-bottom:0; border-top:1px solid #ddd;}
.custom #footer_nav li {margin-bottom:0; margin-top:-0.1em;}
.custom #footer_nav li ul {border-bottom:0; margin-top:0;}
.custom #footer_nav ul.children {margin-top:0.1em;}
If you need further info on the syntax of PHP, XHTML or CSS to understand the info above, please check out Tizag tutorials and W3 Schools.





{ 1 trackback }
{ 24 comments… read them below or add one }
I really thank you for the help you’ve provided.
That’s quite nifty!
i m addicted to ur posts!!!!!!!!
Almost bookmarked each page of ur blog
Excellent, thanks for sharing. I was thinking about this when 1.6 first arrived. :)
-Mig
Great post. Thanks for the info.
You aren’t kidding about how easy drop-downs are in Thesis. I spent days creating a contextualish menu thingee on a client site a few years ago. Now, with Thesis, it took no time. Kills me!
Keep up the good work Kristarella, what little you know of how much you have helped me :) Love your interesting articles and tutorials, keep pushing the boundaries matey :)
David
It’s unique menu of drop down at footer, not usually.
hey….loved the menu..!!
Kristarella,
Would you be so kind as to shed some light on what we should do if we used the wonderful custom solution you instructed in the past for pre 1.6 versions? I just want to make sure all of my menu css still gets pulled in.
Thank you!
Suzi — The best thing to do is to keep your old CSS on hand, but remove it from the CSS file, then copy as much as you can into the new settings on the Design Options page; you can control colours and adjust borders from those settings. Then any CSS you have that you can’t use through the Design Options can be copied back into your custom.css file and change
.custom #tabsor.custom ul#tabsto.custom ul.menu.Hi,
I am trying to add my subpages to my menu, for some reason, I got the About me to add contact under it, but i can’t seem to get it to add any other pages.
Any ideas? You look like a genius with this!
Brian :)
Brian — Usually it’s a case of forgetting to add the pages to the nav menu after assigning them as a child page. That’s what I usually do anyway.
Good one! I was looking for this tutorial all this while. Thanks :-)
Happy New Year!
Once again a great post and I love you Skins. On this site I see you have transparent navigation tabs. Is this easy to do and if so could you please let me know how.
Thanks. Pete
Pete — I believe all you need in custom.css is
.custom .menu li a {background:transparent;}.You’re right! Like everything in life, it’s so simple when you know how :o) Keep up the inspirational work and thanks for a very quick response.
Thanks for the tutorial, I had some fun with it :)
Now I have a crazy question, do you know how to bring the page nav down to the footer using this drop up technic?
WC — you can use
wp_list_pages()the same waywp_list_categories()is used, or if you wanted to duplicate your thesis navigation with pages and categories down the bottom you could usethesis_nav_menu();instead of all the code in the function (but if you did it wouldn’t have the id “footer_nav” anymore, you’d need a different identifier).Hey, I used thesis_nav_menu(); in the function and it’s showing up. (I put a around, it seems to work…)
It looks like the second level drop up is off 1 cell with to the top.. (the child pages)… Not sure what’s the best way to fix it
… Also, how do I get rid of the top menu bar completely?
Thanks :)
Hi I just added this to the custom.css, it fixed the offset :)
.custom #footer_nav li ul li ul {border-bottom:0; margin-top:30px;}
WC — When using
thesis_nav_menu()it would be better not to have it inside anotherul, which is why I said you’d use it instead of all the code in the function, otherwise you end up with a menu inside a menu. Anywho, if you have it working for you, that’s good.To remove the top navigation you need
remove_action('thesis_hook_before_header','thesis_nav_menu');in custom_functions.php.Hi, I put it in a div and give it an id (footer_nav)
thanks for your help! :)
btw, do you have a suggestion to make it into something like this?
http://www.bennadel.com/blog/1.....eBook-.htm
WC — Essentially all you would need is
.custom #footer_nav {position:fixed; bottom:0; }, but as he says in that link, IE doesn’t always play nicely. Not sure what value you’d need to center it perhaps looking up “CSS position” on W3 Schools will tell you.