Showing posts with label blogspot. Show all posts
Showing posts with label blogspot. Show all posts

Tuesday, August 18, 2009

How to Make Drop-Down Labels Menu in Blogger?

If you host your blog on the Blogger (blogspot) platform, and you have significant number of labels on your sidebar, you might be looking for a suitable solution to show them, but also save the expensive space for other elements. These two tasks can be achieved by using the option of displaying your labels in a simple drop-down menu. Many bloggers already use drop-down option for long lists of labels (categories), which minimizes clutter and enables information to be displayed in the sidebar neatly.

While Blogger offers a dropdown menu option for the Archives widget, you will not be able to find an option to do the same for your labels. In this post, we will review two ways you can use to convert your regular Label list into a drop-down list.

Method 1

1. Template Backup. As usual, when you just think about making any changes to the template code, it is strongly recommended to make a complete back up of your existing template. This ensures you can easily roll back and restore your current, working template if you make any mistake.

To make a back up of your current template, go to Layout > Edit HTML in your Blogger dashboard and click the “Download Full Template” link near the top of the page. This will offer the option to save your current Blogger template as an XML file to your local computer. Be sure to save this file in a location you can easily find later.

2. Ensure you have a “Labels” widget in your Blogger template. If you do not have a Labels widget activated in your template, go to Layout>Page Elements and add a Labels widget using the “Add a Gadget” link above your sidebar. Definitely, your posts should be labeled as well to transfer the related content to the activated widget.

3. Go to Layout > Edit HTML in your Blogger dashboard. This time, DO NOT check the "Expand Widget Templates" checkbox!

4. Search for the following code (note that the name of the label in your template might be slightly different):
<b:widget id='Label1' locked='false' title='Labels' type='Label'>

5. Replace the above code, with this:
<b:widget id='Label1' locked='false' title='Labels' type='Label'>
<b:includable id='main'>
<b:if cond='data:title'>
<h2><data:title/></h2>
</b:if>
<div class='widget-content'>
<br/>

<select onchange='location=this.options[this.selectedIndex].value;' style='width:200px'>
<option>Labels</option>
<b:loop values='data:labels' var='label'>
<option expr:value='data:label.url'><data:label.name/>
</option>
</b:loop>
</select>

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

6. Modifying the Widget. To alter the phrase “Choose a label to view” which is visible when the drop down menu is contracted, you will need to go to the Layout>Edit HTML page of your Blogger dashboard and check the “Expand widget templates” box. Then search for this phrase in your template code. Simply alter the wording of this phrase to something more suitable for your blog, being careful not to alter any of the surrounding code.

To clarify, here is the line of code where adjustments will be made. The text which can be altered is highlighted in red:
<select onchange='location=this.options[this.selectedIndex].value;'>
<option>Choose a Label to View</option>
<b:loop values='data:labels' var='label'>



Method 2
As you understand, the first steps of the code modification will be similar to the method 1, so I will skip the introduction, which you need to backup the template first before doing any modifications.

3. Go to Layout > Edit HTML in your Blogger dashboard. This time, CHECK the "Expand Widget Templates" checkbox!

4. Now look for the following code in your template

<b:widget id='Label1' locked='false' title='Labels' type='Label'>
<b:includable id='main'>
<b:if cond='data:title'>
<h2><data:title/></h2>
</b:if>
<div class='widget-content'>

 <ul>
   <b:loop values='data:labels' var='label'>
     <li>
       <b:if cond='data:blog.url == data:label.url'>
         <data:label.name/>
       <b:else/>
         <a expr:href='data:label.url'><data:label.name/></a>
       </b:if>
       (<data:label.count/>)
     </li>
   </b:loop>
   </ul>


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

5.
Note that you need to replace only the part of the displayed code IN BLUE. All the remaining text is provided for easy reference. So, replace the text IN BLUE with the text IN RED below:

<br />
<select onchange='location=this.options[this.selectedIndex].value;'>
<option>Select a label</option>
<b:loop values='data:labels' var='label'>
   <option expr:value='data:label.url'><data:label.name/>
      (<data:label.count/>)
   </option>
</b:loop>
</select>


No matter, which method you choose, at the end of the performed modification save the template and back it up with a new name. Do not overwrite the backup file you created at the beginning, since you want to try the option for some time and decide you do not see any problems or performance drawbacks.


Sources and Additional Information:

Wednesday, December 3, 2008

Dynamic Tree DTree for Blogger Blog

In course of my experiments to bring normally dynamic content in the Blogger blog to the appearance and functionality of the static Websites, I was trying to implement the Blogger hack, allowing displaying the blog Table of Content in the Windows Explorer similar interface. While there are multiple scripts available online for this modification, I had to try several of them before I actually found one, which worked right away with relative simplicity. It is my pleasure to offer it to you. All credit for this excellent script is to the author of The Blogger Guide. I will repost the article without modification in respect to the script developer.

A tree control (i.e. the GUI element found in the left pane of Windows Explorer) provides a useful way of organizing a set of hierarchical items. This article will present a method to incorporate such a tree control in to Blogger blogs.

Before we proceed, let’s take a look at how our final tree will look like.


Now let’s see how to include a tree like the above in your blog.

Step 1
First step is to include two resources, a JavaScript file and a CSS file, in to the Blogger template. Copy the following two lines of code and insert them in to the head section of your template.

<link href=’http://thebloggerguide.googlepages.com/dtree.css’ rel=’StyleSheet’ type=’text/css’/>
<script src=’http://thebloggerguide.googlepages.com/dtree.js’ type=’text/javascript’/>


You can copy it immediately under the <head> tag as shown in the figure below. (These two resources are hosted on the Blogger Guide companion site. Don’t worry, there is no tracking code or any thing of that sort there. It’s used purely for hosting files referred to from these articles)


Save your template and exit Edit HTML mode.

Step 2
Next step is to write the code necessary to create the tree. I will first present a sample code and then explain it.

<div class="dtree">

<p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p>

<script type="text/javascript">
<!--

d = new dTree(’d’);

d.add(0,-1,’Favorite Articles’);
d.add(1,0,’3 Columns’);
d.add(2,1,’3 Columns Explained’,’http://bguide.blogspot.com/2008/02/three-column-templates-explained.html’);
d.add(3,1,’Skeleton of a Template’,’http://...’);
d.add(4,1,’Adding a Third Column’,’http://...’);
d.add(5,1,’Layout Wire Frame Editor’,’http://...’);
d.add(6,1,’3 Columns with LR Sidebars’,’http://...’);
d.add(7,0,’Blog Traffic’);
d.add(8,7,’How to Monitor Visitors’,’http://...’);
d.add(9,7,’Feedjit’,’http://...’);
d.add(10,7,’Exclude Your Traffic from GA’,’http://...’);
d.add(11,0,’Customizations’);
d.add(12,11,’Add a Custom CSS class’,’http://...’);
d.add(13,11,’Related Posts Table’,’http://...’);
d.add(14,11,’Limit Widgets to Specific Pages’,’http://...’);
d.add(15,1,’3 Column Step by Step Guides’,’http://...’);

document.write(d);

//-->
</script>
</div>


The first line defines a generic div element and applies the class dtree in to that. This CSS class is defined in the dtree.css file which we included in Step 1 above. Next line inserts two buttons (in fact, links) to Expand and Collapse all the nodes in the tree. Thirdly, you find a Javascript enclosed within a <script> element. The first line in the script, d = new dTree(’d’), creates a new tree object to which we can insert nodes. The following lines which start with d.add(...) are the statements that insert all the nodes in to the tree. Then the last line of the script, document.write(d), renders the created tree on to the browser.

The add() function of the dTree takes in several parameters. The first 3 parameters are required (i.e. you must provide values for them) and the other parameters are optional. The above example uses the following 4 parameters.

  • Node ID - A unique numerical ID number. Assign a sequentially increasing number to each new node.
  • Parent Node ID - If you want to create a child node, then the ID of the parent node should be given here. This will be ’-1’ for the root node. (See the first d.add(...) line in the example)
  • Node Name - A textual description for the node
  • Node URL - If you want the node to link to some resource (e.g. an HTML page or some online image), provide the URL of the that resource as the 4th parameter.
For a full description of the add() function see here. You don’t have to provide consecutive (or adjacent) IDs for all the child nodes at a given level. For example, node 15 of the above snippet is attached as a child of node 1 called ’3 Columns’. You can have the nodes anywhere as long as you maintain the uniqueness of the node IDs and provide the correct parent node IDs. Step 3 Once you finish adding the nodes, copy the entire code starting from the <div class="dtree"> to the corresponding </div>. Then insert the entire code using an ’Add HTML/Javascript Element’ widget of the ’Add Page Element’ option. Place the widget where you want the tree to appear. Save the template and view your blog. You will have the tree sitting nicely in your blog! One limitation is the fact that node names do not wrap at the edges. So you have to give names that fit withing the width of the containing sidebar (or whatever location). Let me know what you think of it and also if you come across any problems when installing it.

Acknowledgment: I have used the free tree control offered by Geir Landr҆ at Destroydrop. The original files have been slightly modified to make them available online, to be used inside Blogger.

Note: You are free to use the resources used in Step 1. But if you do use, please link to this article from your blog.

If you want to see the practical implementation of this script, you can visit my new blog Data Recovery Techniques.

Thursday, November 6, 2008

How to Remove NavBar in Blogger

There might be multiple reasons, why would you like removing Blogger Navbar from the top of your page:

  • This bar highlights that you are part of the Blogger community, and you might not want emphasizing that.
  • The bar might not fit well to your template design.
  • Blogger has started random advertisement above the Navbar and this has taken valuable space on you blog page.
Due to the simple fact the fact that the Blogger TOS (Terms of Service) do not specify that keeping Navbar on the blog is a mandatory feature of the Blogger account holder, you have no legal or ethical restrictions on the Navbar removal.

Fortunately, removing the Navbar is a quite easy task, and it can be done in different ways.
1. Go to your blogger Dashboard and select Layout.
2. Click Edit HTML.


Method 1

Find the following record in the template layout
<b:skin><![CDATA[/*
Paste this simple code
#navbar-iframe { display: none !important; }


Method 2 (By Aditya)
Look for <b:skin> and paste the following after that:
/* By Aditya http://the-lastword.blogspot.com/ ----------------------------------------------- */ div.navbar { opacity:0.0; display:none; }


Method 3 (By Praveen)

Look for <b:skin> and paste the following after that:

/* By Apnerve http://www.apnerve.blogspot.com ----------------------------------------------- */ #navbar #Navbar1 iframe { display:none; visibility:none; }



Method 4
Just add the following lines anywhere in your Blogger template [enclosed by <style> tags] and the blogger banner will be gone forever.
#navbar-iframe { height:0px; visibility:hidden; display:none; }


Additional Reading:
http://blogger-tricks.blogspot.com/2008/10/hide-new-blogger-xml-navbar.html
http://www.cyberspirits.net/2008/06/hiding-navbar-in-blogger-how-to-hide-navbar-in-blogger/
http://www.jaystech.com/2008/08/how-to-hide-blogger-navbar-in-old-new.html
http://labnol.blogspot.com/2007/01/how-to-hide-blogger-navbar-in-new.html