28 November 2006

DropDown Menubar

Today I will present my first hack, a dropdown menubar for Blogger Beta.
Feel free to criticise my instructions in case they do not provide enough information. Before we start the engines, I want to thank Avatar, who encouraged me to write these thoughts down. =)


I used Hoctro's 'Labels as Tabs'-hack, but in the end, I felt the need of some sort of drop down-solution. Take a look below my header, you should see it there. Well, doesn't look that special at first, does it? So just hover over the different sections to witness a nice drop down-functionality that enables us to put all kind of stuff in there, e.g. category links, label feeds, blogrolls, linklists,...

I wanted to get rid off my old tabs and replace it with this menubar under the condition that it would contain widgets. Because I am no coder, this idea was followed by a few try&error-experiences, but now I can happily say that I got it to work. The initial version of the bar can be found here.

So let's get going, shall we?


Step 1: The Javascript

Simply copy the following line into the head-section of your template:

<script src='http://non.alastor.googlepages.com/chrome.js' type='text/javascript'/>

Make sure that you don't insert it into the style definitions. Of course you can also replace the link if you decide to upload this file to another host.

Step 2: The CSS-definitions

Now we will define the look of the menubar, so click on your Edit HTML-tab and go to your style section. Depending on the desired color of your bar, you will have to copy one of the following definitions:

chromestyle.css - silver
chromestyle2.css -blue
chromestyle3.css - green
chromestyle4.css - red

Simply paste the code into the stylesheet, before the 
]]></b:skin>

Step 3: Positioning the menubar

Okay, now we should be able to insert the last bits of our code to place the menubar. So let's talk about the possibilities we have: theoretically, we could put the bar everywhere, but I want to show you two ideas of inserting the menubar:

a) below the header, over the rest of your content:

This is the main idea behind the concept, making it to one of the most important elements on your site. Search for the end of the header-section and the beginning of your content-wrapper, this is the place where the following code goes in:

<div class='chromestyle' id='chromemenu'>
<ul>
<
li><a href='http://YOURBLOG.blogspot.com/'>Home</a></li>
<li><a href='#' rel='dropmenu1'>
Content 1</a></li>
<li><a href='#' rel='dropmenu2'>Content 2</a></li>
<li><a href='#' rel='dropmenu3'>Content 3</a></li>
<li><a href='#' rel='dropmenu4'>Content 4</a></li>
</ul>
</div>

<script type='text/javascript'>
cssdropdown.startchrome("chromemenu")
</script>


b) instead of the Blogger navbar on the top:

An interesting approach: replacing the navbar with your own, personal menubar. It's not that difficult. You will have to add this line of code into your stylesheet:

#navbar-iframe {display:none
}


Then you will have to search the opening body-tag and paste the code from step 3.a there.

This is it. We will customize the contents of the menubar in the next step.

Step 4: Filling the menubar with your widgets

As you can see, the menubar has now five elements in it: Home and Content 1-4. Rename the contents to your preferences. You can also add other links or more content-elements (these will be our dropdown-menus) by adding new lines to the chromestyle-div.
Decide which widgets you want in your menubar. I assume that feed-links, blogrolls, category links, etc. are ideal candidates. In order to get a widget in there, go to its code and add the bold lines of code in there:

<b:widget id='...' locked='false' title='...' type='...'>
<b:includable id='main'>
<div class='dropmenudiv' id='dropmenu1'>
<div class='widget-content'>
.
.
.
</div>
</b:includable>
</b:widget>


Of course, the ID 'dropmenu1' should only be used once. You then have to change the number to dropmenu2, dropmenu3, etc.
Don't forget to delete the following line out of all widgets you put into your menubar, otherwise the layout won't look good:

<h2 class='title'><data:title/></h2>

It should work fine with plain linklists and blogrolls, but you will face some sort of strange layout, e.g. when you want to display your categories up there. For this reason I have prepared code that should fit your desires:

a) Categories in the Menubar:

As far as I can tell, the menubar only shows one link in a line. So it gets screwed when you simplay put up a category-widget, because the label count goes in an extra line. My workaround is to put the label count inside the link:

<b:widget id='Label1' locked='false' title='Categories' type='Label'>
<b:includable id='main'>
<div class='dropmenudiv' id='dropmenu1'>
<div class='widget-content'>
<b:loop values='data:labels' var='label'>
<b:if cond='data:blog.url == data:label.url'>
<data:label.name/> (<data:label.count/>)
<b:else/>
<a expr:href='data:label.url + "?max-results=100"'><data:label.name/> (<data:label.count/>)</a>
</b:if>
</b:loop>

<b:include name='quickedit'/>
</div>
</div>
</b:includable>
</b:widget>


b) Feed Links-Widget:

I guess I am not the only one using PurpleMoggy's label feed-solution. If you try to pull that up to the menubar, you will soon face the problem 
that every feed icon goes in an extra line. For this reason I've put up a customized label widget that offers label-feeds and standard post/comment-feeds as well:

<b:widget id='Label2' locked='false' title='Newsfeeds' type='Label'>
<b:includable id='main'>
<div class='dropmenudiv' id='dropmenu2'>
<div class='widget-content'>
<a href='http://YOURBLOG.blogspot.com/feeds/posts/default/-/' target='_blank' title='Subscribe to Posts'><img src='http://non.alastor.googlepages.com/rss_icon.gif'/> Posts</a>
<a href='http://YOURBLOG.blogspot.com/feeds/comments/default/-/' target='_blank' title='Subscribe to Comments'><img src='http://non.alastor.googlepages.com/rss_icon.gif'/> Comments</a>

<b:loop values='data:labels' var='label'>
<a expr:href='"http://YOURBLOG.blogspot.com/feeds/posts/default/-/" + data:label.name' target='_blank'><img src='http://non.alastor.googlepages.com/rss_icon.gif'/> <data:label.name/></a>
</b:loop>

</div>

<b:include name='quickedit'/>
</div>
</b:includable>
</b:widget>


Fine. We are done...for now. You can easily play around with the CSS
to change the look or add new elements to the menubar.
I hope you found my instructions useful, please let me know if you like this hack.

Update:

Here is an additional method to get content into the menubar:

Vivek Sanghi presents a way to get a list of recent posts into the menubar, which is pretty useful! Visit his post concerning this matter to see how!

Cheers!

33 Kommentare

Ramani meinte...

Welcome to hacking! Good job.

Aditya meinte...

Now that's a very good explanation of the script and implementation, especially the part where you explain how to use it for different types of things ...

Not really a hack, but good thinking! Keep it up! :)

Manas meinte...

Thanks.. my menubar is up and running... :)

Alastor meinte...

@Ramani:

Thanks!

@Aditya:

Thanks for stopping by! Well, for the most part it's logical thinking, because I am not very experienced in coding - I have to figure out a lot of stuff by trying around.

@Manas:

You're welcome! Glad you like it!

Vivek Sanghi meinte...

"it's logical thinking, because I am not very experienced in coding - I have to figure out a lot of stuff by trying around."

Reminds me of a quote from some one:

"The number of possibilities in the mind of a beginner are many but in the mind of experts, its few."

Not to undermine the importance of experts in anyways though :D Good work!

Deb meinte...

I have a black template and the menubar does not fit in, how do I adjust the color to match my template?

Thanks.

Alastor meinte...

Well, considering the fact that your template has totally different colors, I would recommend downloading the two picture files the menubar consists of (chromebg.gif and chromebg-over.gif) and changing the colors to your preferences. The links to the pictures can be found in the CSS-parts I posted.

Deb meinte...

Great, I'll go buy a graphics program. There should be an easier way to do it, I'm trying to eliminate as much script as possible.

Alastor meinte...

Why not using free solutions like GIMP? Even the preinstalled Paint should be more than enough...

If there was an easier way, I would have offered 40 instead of 4 colors^^

Deb meinte...

I'll figure it out, eventually. It isn't enough to prevent me from using the hack though, thanks. I get a kick out of rolling my mouse over the menubar.

Alastor meinte...

You're welcome, Deb!

Skanky Jane meinte...

Thank you Alastor!

I am really enjoying this hack. I have customised it to suit my tastes (it is very amenable to customisation). I agree with the former comment about the fact that you have provided excellent instructions especially with the method for adding particular widgets to the drop down menus.

I would like to combine widgets and recent posts together in this hack (i.e. your hack and Vivek's combined) so I have some work ahead of me yet!

This is great though - I found yours the best suited to my needs - i.e. the simplest and most customisable way to add menu tabs aand the widgets add is very clever!

Cheers,
SJ xx

Alastor meinte...

Hi, Skanky Jane!

I am glad you like it.
As you can see, I have combined my version with Vivek's approach - like you said, the advantage of this hack is that it can be customized very easily.

Thank you for your positive feedback,
best regards!

Skanky Jane meinte...

Dear Alastor,

Still digging this hack however I have a wee problem in that my drop down menu comes down under the top blog post and by the drop down list closes whenever I move the cursor to the third item down on that list.

Any ideas as to what I might have done wrong or need to do to fix this?

Many thanks,
SJ xx

Skanky Jane meinte...

Dear Alastor,

I have stopped the drop down menu from disappearing before I can cursor over the items in it by adding "padding-bottom' like this:

.chromestyle{
width: 99%;
margin-left: 1%;
padding-bottom:100px;
}

Not sure this is the best way but it seems to work. It seems the problem was that (because I aligned my menu text 'left') the drop down menu hung under the blog post - the cursor must have been confused thinking it was not on the list anymore.

SJ xx

Alastor meinte...

Hi Jane,

sorry that I didn't get to you in time. Looks like it's working now, congratulations!

Cheers!

Phileo meinte...

Hi Alastor,

This drop down menu tabs is a great hack!
One question - is it possible to force the drop down list to be displayed just below the menu tab?

I don't like how the dropdown list overwrites my blog header-banner whenever I am at the very top of my blog page.

Alastor meinte...

Hello Phileo,

I just took a look at your blog, but it looks fine to me. The menubar doesn't overwrite the header over here, instead the drop down list appears just below the menu tab (like it has to).

Maybe you could email me a screenshot of the problem?

Phileo meinte...

Hi Alastor,

I've figured out the problem. If my browser is too short in height, then the dropdown list will be shifted up in order to fit inside the browser. Therefore, it will overwrite the header banner.
I increased the height of my browser, and voila - problem solved !

Thanks again for this great hack!

Chhaya meinte...

i cant tell you how grateful i m. i used your hack in my Blog for profile, label, archive, links and i love the way it cleared my side bars. thank you so much

Alastor meinte...

Greetings, Chhaya!
Glad you like it. You're welcome! =)

underbeats meinte...

Hello bud...
Nice hack you posted here, i got it to work but i have a problem when trying to create the drop downs.
I don't know how to insert a drop down in the buttons of the main menubar.
It would be good if you can help me!
Thanks a lot.

underbts.

underbeats meinte...

Hey man, I did it!
Thank you a lot.
Cheers.

Alastor meinte...

Hi, underbeats!
Congratulations (and sorry that I didn't get you in time)! ;-)

underbeats meinte...

Thank you anyways =)
Good Luck!

Kevin meinte...

I am trying to implement this hack but for some reason the drop-down is not dropping down directly below. It is offset a little bit. What am I doing wrong? Can you help?

http://seaksutest.blogspot.com/
http://seaksu.blogspot.com/

Thank you,
Kevin

Agus Sanjaya meinte...

Hey... first of all thanks for the great hacks... I have put it in my blog... And I have managed to limit the number of labels that you want to show... maybe you have a lot of labels and you don't want to show it all... I use your hacks and Ramani's. Visit my blog here .

Anonym meinte...

hello- i am a true amateur to this and can't seem to get place the code properly. can you tell me where each string goes exactly? i'm using the classic template, white.

thank you very much in advance,
-kevin

Alastor meinte...

Hello Kevin,

I'm afraid to say that I can't help you out here because you won't be able to use this hack if you are still over there with a Blogger Classic template.

Best regards,
Alastor

ISET meinte...

Hi Alastor,

Very very useful and great post. Thanks... :D

On the same note, I wonder if you could help me with the dropmenu problems.

The first one is (I have successfully installed my label there) my lable menu drop from the top of the page.

The second one is I tried to put my link to the menu, but for some reason it always got redirected back to my page.

Is there a work around that can solve this problems? Again thank you, Alastor... :D

Best regards,

Iset

Alastor meinte...

Hello Iset,

Thank you for the positive feedback!

I haven't dealt with this hack for a while, but you are not alone with the problem. The reason for the menu to drop from the top of the page is simply that there are too much elements in the list so that it doesn't fit the screen anymore.

I think that the menu shouldn't be that long for cosmetic reasons anyway, so there are two ways to take action on that: you can either increase the height of your browser so that the list doesn't overwrite your banner, or you can follow these instructions to limit the number of items shown in the menu.

Concerning the second part: what link do you mean? Do you want to have a link pointing to your blog?

Best regards,
Alastor

ISET meinte...

Hi Alastor,

Thanks for the guidance. It works!

For the second problem that I have, I have fixed it. Its because improper link.

Again thank you... :))

Best regardds,
Iset

Herbert Wong meinte...

HI Alastor,
I followed your instructions but could not get a menubar at all on my blog.Wonder anyone has the same problem?