Blogger’s data tag “label.count” is only available within Labels widgets.
To get the label count (post number per label) outside the widget, you need to use JavaScript.
This is the simple JavaScript snippet: store the pair of the “Label Name / Count” from the Labels widget into an object (aka associative array).
JavaScript
var labelCounts = {};
var label = document.getElementById('Label1');
// 'div ul li' is for List, 'div>span' is for Cloud
var elms = label.querySelectorAll('div ul li, div>span');
[].forEach.call(elms, function(elm) {
if (elm.childElementCount == 2) {
labelCounts[elm.children[0].innerHTML] = Number(elm.children[1].innerHTML.replace(/[()]/g, ''));
}
});
Then, you can get the count of labelName by:
JavaScript
labelCounts["labelName"]
Prerequisite
- Labels widget ID is “Label1”.
- Check “Show number of posts per label” in “Configure Labels”.
How can I add it to blogger?
ReplyDeleteYou can add in ″Edit HTML″. I use this function for sorting breadcrumbs. See
ReplyDeletehttps://nkurilog.blogspot.com/2017/12/blogger-sort-breadcrumbs-by-label.html
Hi!
ReplyDeleteThis shows all the labels but how to get the all posts of a specific label?
label (100)