Stubborn Fanatic

Avatar

Documenting Tech Fanaticism


You're browsing: Home » blogger, blogging, my hacks » Blog article: Show recent posts under a label (category) in a drop-down from horizontal navigation bar

Show recent posts under a label (category) in a drop-down from horizontal navigation bar


Dear readers,

Based on the new JSON format and the JavaScript code for displaying recent posts from Hans of beautiful beta, I now present horizontal navigational menus with auto (activates on mouse hover) drop-downs which display the most recent posts under each of your labels (say categories).

To see this in action take your mouse cursor to the “Beta Hack” or “Hack News” section in the navigation bar in my blog’s head section (i.e. just below the hidden navbar).

This hack will allow readers to browse a particular label category by simply clicking on the label name in the menu or go directly to a specific post under that label by clicking the post title that appears in the drop-down. Therefore, this does not take away the navigational advantage of horizontal tabs in header and at the same time it allows a blog author(s) to give exposure to the most recently updated posts from various label categories.

I found the code for this drop-down menu on dynamic drive at the following link. (Don’t forget to visit this link to learn more about customizing this code according your preferences.)

Warning : If you are not familiar with your template code and HTML I recommend you create a backup copy of your template and/or first try this hack on a test blog.

The Hack

Here is the procedure for installing this hack in your blog:

1. JavaScript source

Copy-paste this line of code into the <head> section of your template, preferably just before </head>

<!– /***********************************************
* Chrome CSS Drop Down Menu- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/ –>
<script src=’http://stubb.fanatic.googlepages.com/chrome.js’ type=’text/javascript’/>

To download this file for modification/alternate hosting, right-click here and save to your hard-drive.

2. Including the CSS

Copy-paste any one of these CSS style codes just before the ]]></b:skin> line in the header section of your template. The images (links in the code) are hosted in my test blog, so if you wish to, you can download the images and host them in your own blog.

CSS style 1: Click here to view/download the code.

CSS style 2: Click here to view/download the code.

CSS style 3: Click here to view/download the code.

CSS style 4: Click here to view/download the code.

3. Code in the HTML widget.

Copy-paste this code into a HTML widget from the page layout section (using add a page element feature). You should ideally create this widget in the top most region of your page (like in my blog).

Click here to view/download the widget code.

Modifications:

- Each drop down menu’s code has been demarcated with indicator comments in <!– … –> If you wish to add additional drop downs, follow the usual flow of the code i.e. a fourth drop down will have

<li><a href=”[label link]” rel=”dropmenu4“>[label name]</a></li>

in the very first div, and

<!–4th drop down menu –>
<div id=”dropmenu4″ class=”dropmenudiv” style=”width: 150px;” >

[the js code for calling the post titles]

</div>

to include the function call for displaying post titles.

- Replace all the […]s with the appropriate text as indicated. For example, replace [Label feed URL] with the feed URL of your label which will be of the following format

http://stubborn-fanatic.blogspot.com/feeds/posts/default/-/[LabelName]

If the label name is not one single word and has got spaces between words, replace the spaces with %20

http://stubborn-fanatic.blogspot.com/feeds/posts/default/-/Label%20Name

- The value of “numposts” which by default equals 5, can be modified but I do not recommend increasing it, as long drop-downs might look ugly.

The hack is now installed. Do let me know if you face any problems.

Update: Alastor from nonstop nonsense (but it makes quite a bit of sense here :) ) has used the same code from dynamic drive to convert entire widgets into drop-downs! Please visit his blog to learn how. The “Labels” and “Translate” section in my header navigation bar are using this hack.


No related posts.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
PDF version
  • Kevin
    Vivek,

    I am trying to implement this hack and have done so successfully on one blog.

    However, on another blog (and its test)I cannot get the drop down to drop directly below the tab, it is slightly offset. Any ideas why this might be?

    Thanks,
    Kevin
  • The Gibbous Loon
    This is a beautiful hack, Vivek. It's along the lines of what I've been looking for for a very long time. But I'd like the tabs to look different and I can't figure out how to do that. For example, I'd like to do a solid block of a custom color behind the text, but I can't figure out how to adjust the .css to do that. Or, I'd like to make a gif with the text already in the gif, but again, I don't know how to do that. Or adjust the width of the line of labels.

    Any advice you could offer would be much appreciated.
  • Kartik
    Hi Vivek,
    Kartik here.
    Actually I use old blogger and my account has not yet been upgraded to the new blogger.
    Can this hack work in the old blogger too.
    Awaiting your reply!!!


    Regards,
    Kartik.
  • Brainiac
    Three Levels Navigation Bar Hack: Vivek, would be well using this navigation bar of three levels,

    1º options
    2º labels
    3º Post Titles

    Check It CSS Drive three Levels
  • Clumsy Hacker
    Thanks anyway Vivek for your help. Guess will have to KIV this hack for the time being. :(
  • Vivek Sanghi
    @Clumsy Hacker:

    I don't know how restricting of a blog will affect the feed fetch etc as the admin code that controls all this is at the blogger back-end and not exposed. As far as I know there is no workaround for this.

    And yes it is json and not jason. My bad...I went with the pronunciation :)
  • Clumsy Hacker
    Hi Vivek,

    I finally found out what is wrong !!

    In order for the feed to work, I need to set the blog up so that anybody can read the blog. If I chose only selected reader, it doesn't work, even for that selected reader.

    Hmmmm .... if this is the case, then, I can't implement this hack in my blog cos I intend to restrict my blog to certain people.

    Do you know of any workaround, if this is true?

    Cheers
  • Clumsy Hacker
    Hi Vivek,

    I reloaded my template with your hack again (without any changes made since last time) and now I got two error messages under two different scenarios:

    1) When I set the Allow Blog Feed (under Setting -> Site Feed) to "None", I get the "HTTP 404 - File not found" error page.

    2) When I set it to "Full", I get a pop up screen showing this message: "Internet Explorer cannot download Show Time from myshorttakes.blogspot.com. Internet Explorer was not able to open this Internet site. The requested site is either not available or cannot be found. Please try again later."

    Was wondering if this shed any light?

    BTW, when I mouse over the tab, in both cases, I still do not see the drop down list.

    Cheers
  • Clumsy Hacker
    Hi Vivek,

    Thanks for your reply. So sorry to continue to trouble you. I did all the necessary checks and these are what I have in my template:

    Script file:

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

    URL for the feed:

    <li>Show Time</li>

    <div class='dropmenudiv' id='dropmenu2' style='width: 150px;'>
    <script language='javascript'>var numposts = 5;</script><script src='http://myshorttakes.blogspot.com/feeds/posts/default/-/Show%20Time?alt=json-in-script&callback=showrecentposttitles'/>

    The above seemed the same as what you wrote in your post. Maybe I missed out something?

    (Noticed that it was json, but you mentioned jason?)

    Cheers
  • Vivek Sanghi
    @Clumsy Hacker:

    Firstly I recommend using this format for feeds:

    http://[YourBlog].blogspot.com/feeds/posts/default/-/[labelname]

    Second if there is a space in the label name use %20 (please read my post carefully.)

    Third the feed url you have specified might be incomplete. Hve you used ?alt=jason in the end. (if not read the code given by me carefully)

    Fourth and one that can be easily overlooked. Are you using the javascript provided by me. It contains an additional function that fetches post titles from a feed. I am not sure if Alastor's script file has that function.

    Let me know if it still does not work after taking care of all these points.
blog comments powered by Disqus