- Add the Labels gadget if is not yet added
From your dashboard, click Layout -> Add a Gadget and select Labels - Add an HTML gadget. This is where you will create your hierarchical labels.
From your dashboard, click Layout -> Add a Gadget and select HTML/Javascript - Ensure that the Labels gadget comes first before the HTML gadget in your layout.
From your dashboard, click Layout and arrange your gadgets by dragging them to the desired location so that the Labels gadget is on top or comes first before the HTML gadget - Update the Template
-
Add the dtree javascript.
From your dashboard, click Template -> Edit HTML -> Proceed and check Expand Widget Templates. Copy and paste this code<link href='https://sites.google.com/site/efekefek/file-js/dtree.css' rel='StyleSheet' type='text/css'/> <script src='https://sites.google.com/site/efekefek/file-js/createdtree.js' type='text/javascript'/>
after this tag
<b:skin><![CDATA[/*
- Remove the Label widget content
Find the Label widget code. It looks like this<b:widget id='Label1' locked='false' title='Labels' type='Label'> <b:includable id='main'> ... </b:includable> </b:widget>
Replace the code inside <b:includable id='main'> and </b:includable> with this code<script type='text/javascript'> var labelCountMap = {}; <b:loop values='data:labels' var='label'> labelCountMap ["<data:label.name/>"] = "<data:label.count/>"; </b:loop> </script>
- Save template
-
Add the dtree javascript.
- Prepare the code of the Hierarchical Labels
Copy the code below and replace the data with your own Labels. The data is in format
parentLabel: { subLabels }
The subLabels are comma separated. If the parentLabel doesn't have subLabels, replace it with {}.
<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"> <!-- function isEmpty(obj) { for(var prop in obj) { if(obj.hasOwnProperty(prop)) return false; } return true; } function addMap(d, startingNode, parentNode, map) { for (var key in map) { if (isEmpty(map[key])) { d.add(startingNode++,parentNode,key+' ('+labelCountMap[key]+')','/search/label/'+key); } else { d.add(startingNode++,parentNode,key+' ('+labelCountMap[key]+')','/search/label/'+key); startingNode = addMap(d, startingNode, startingNode-1, map[key]); } } return startingNode; } var data = { 'Label 1' : { 'Label 1.1' : {}, 'Label 1.2' : { 'Label 1.2.1' : {} }, 'Label 1.3' : {} }, 'Label 2' : { 'Label 2.1' : {}, 'Label 2.2' : {} }, 'Label 3' : {}, 'Label 4' : {}}; d = new dTree('d'); d.config.useLines = true; d.config.useIcons = false; d.config.inOrder = true; d.add(0,-1,''); addMap(d, 1, 0, data); document.write(d); //--> </script> </div>
- Paste the code in the HTML widget
From your dashboard, click Layout and Edit the HTML widget. Paste the code inside Content and Save
Wednesday, May 9, 2012
How to create Sublabels / Hierarchical Labels in Blogspot
I always wanted my label section to look like the archive section where labels can have hierarchy and the number of posts is displayed beside each label. I learned how to create the hierarchical tree from this blog but the nodes have to be added one by one and the number of posts per label are not displayed so I tweaked it a little to suit my needs. Here are the steps:
Subscribe to:
Post Comments (Atom)
I tried your code. It works well with the first 5 tags. But No more. Do you know why.
ReplyDeleteIt should work with any number of labels. You just need to add the labels in the data. For example, if you want to add Label 5 and Label 6, update the code this way:
ReplyDeletevar data = {
'Label 1' : {
'Label 1.1' : {},
'Label 1.2' : {
'Label 1.2.1' : {}
},
'Label 1.3' : {}
},
'Label 2' : {
'Label 2.1' : {},
'Label 2.2' : {}
},
'Label 3' : {},
'Label 4' : {},
'Label 5' : {},
'Label 6' : {}};
Also make sure that the format is correct - no extra or missing commas.
Hello,
ReplyDeleteI am not sure why it is not working for me. I made changes as per steps , I am getting the open all and close all widget, but there is no post coming ..it doesn't have anything.
you can check http://wizardofjaipur.blogspot.kr/2015/05/how-to-make-volte-device-part-1.html
Your Labels gadget might be located below the HTML gadget. Make sure to follow Step 3.
Deleteits not working
ReplyDeleteThank you for your insight post.
ReplyDeleteI practiced for about 2 weeks to learn(and web programming)
I finally made the Hierarchical label.
and I wrote it on my blog(Korean, English Version)
English
http://stackrefactoring.blogspot.kr/2016/03/how-to-create-hierarchy-labelstree.html
Korean
http://stackrefactoring.blogspot.kr/2016/03/blog-post_30.html
Hi thank you both!
DeleteI'm now able to sorting my blogs really easily!
What does it mean to "replace the data with your own Labels"?
ReplyDeleteI have the same problem as CSR, and I followed instruction 3 correctly (but perhaps it's a problem that I had another Label widget underneath the HTML widget ..?)
DeleteIs this the kind of thing that's meant to be there?
Deletevar data = {
'Short stories' : {
'Humorous' : {},
'Earnest' : {}
},
'Essays' : {
'Philosophy Essays' : {
'Ontology/truth' : {},
'Meta-ethics' : {},
'Philosophy of Mathematics' : {}
},
'Political and Economic Essays' : {}
},
'My Bleak Memoirs' : {},
'Diary Entries' : {},
'Poems' : {},
'Plays' : {},
'Lists' : {},
'Sports journalism' : {}};
Yes, the code above is what I meant by "replacing you data with your own labels". You may be right that multiple Label widgets is your problem but I am not sure. Just try removing the other Label widget first.
DeleteHi There Mr Admin
ReplyDeleteI'm stuck after applying all these 6 steps, when only open and close link appeared but not the others
is the css and js link still valid or not?
have i done wrong somewhere?
thanks for your help in advance
It is no longer working. Show me why in your blog it is still working!
ReplyDeleteThank you
Very nice post to keep sharing.. Thanks for giving very nice information from your post.. Oracle Training in Chennai | Oracle Training institutes in Chennai
ReplyDeleteGood..
ReplyDeletesnowflake interview questions and answers
inline view in sql server
a watch was sold at loss of 10
resume format for fresher lecturer in engineering college doc
qdxm:sfyn::uioz:
java developer resume 6 years experience
please explain in brief why you consider yourself suitable for the position applied for
windows 10 french iso kickass
max int javascript
tp link router password hack
Very Nice...
ReplyDeleteinternship in chennai for ece students with stipend
internship for mechanical engineering students in chennai
inplant training in chennai
free internship in pune for computer engineering students
internship in chennai for mca
iot internships
internships for cse students in
implant training in chennai
internship for aeronautical engineering students in bangalore
inplant training certificate
it is best blogs for you...!!!
ReplyDeletepaid internships in pune for computer science students
machine learning training in chennai
data science internship in chennai
dot net training in chennai
kaashiv infotech chennai
internship for aeronautical engineering students in india
internship in automobile industry
big data internship in chennai
machine learning internship in chennai
internship in chennai for it students
useful information..nice..
ReplyDeletedevops-engineer-resume-samples
digital-marketing-resume-samples
digital-marketing-resume-samples
electronics-engineer-resume-sample
engineering-lab-technician-resume-samples
english-teacher-cv-sample
english-teacher-resume-example
english-teacher-resume-sample
excel-expert-resume-sample
executive-secretary-resume-samples
I've followed those steps but it didn't work.
ReplyDeleteAnd is it possible for those tags to be dynamically created. Like the regular ones. When I create a new message, I would just enter the tag in some nested format like
label 1 {label 1.1}
and it would be added to the widget.
Thank you.
Nice Blog. Thanks for sharing with us. Such amazing information. Get Hang Tag Printing From PrintMagic and move away from boring and plain marketing materials. PrintMagic offers several customization options for water bottle hang tags and you can print them in different sizes ranging from 1.5" x 3.5” to 4" x 6”. Pick from a rectangle or square shape with the option for square or rounded corners.
ReplyDeleteThanks for these kind of posts, its really appreciated and keep updating your posts.
ReplyDeleteRectangle Stickers