Update January 18th 2012: A newer and easier to install version 2 here, you should consider using it.
Threaded commenting is a much wanted feature in Blogger. There are 3rd party commenting solutions with threading. Wordpress has threaded commenting built in. But what about threading in native Blogger comments?
When googling Blogger comments hacks, for completely other reasons, I came across this Threaded Comments in Blogger article. However the hack looked a bit complicated, template needed big changes, and I did not want that. And, according to some comments, installation to new templates was not straightforward. I thought, maybe it could be done with fewer changes and code that was easier to maintain. I felt like my mind could not rest before I figured out how to do it. :) So I had to find a solution, and finally I did, here it is. Thanks to Sham for the idea.
This hack works for the (current) layout templates (October 2011). Don't know about classic templates. Does not work with dynamic templates, because they display comments completely differently, getting their data dynamically from comments feed.
How to install Threaded comments
Update January 18th 2012: A newer and easier to install version 2 here, you should consider using it.
You must install my Highlight author comments and Reply to comments hacks first. After installing those, edit template html, and paste this just before </body>:
In the script there are two values, 300 and 20, that you can change to control the maximum indent amount (300 in my code) and the indent of one "step" (20 in my code). Defaults should be quite good. You can also change these values afterwards.
Save template and enjoy. It is almost like magic :)
Code "threads" the comments either by parsing link <a href="#link to comment"... or by parsing @username from message field. A reply containing "@username" is positioned after latest username's comment (which timestamp in earlier than in reply) or for immediate previous comment, if it is from username, on the list before reply.
If you just want to test how the threaded comments work, please don't do it in this post, I will delete totally irrelevant comments. But you can do the testing here: Playground for Blogger threaded comments. Thank you.
Just another blog with Blogspot hacks and tips, made/customized by me.
Showing posts with label hack. Show all posts
Showing posts with label hack. Show all posts
Friday, October 7, 2011
23
Threaded commenting with Blogger native comments
Thursday, October 6, 2011
0
Reply to Blogger comments hack
Update January 18th 2012: A new and easy to install threaded commenting hack version 2 includes this hack's functionality, you might consider using it.
There is one hack with variations circulating in internet which gives you the opportunity to reply to individual comments in Blogger. There are some shortcomings in that code. It always uses a popup and the popup does not position (scroll) to the comment form when opened, this is a bug and annoying if there are many comments. You can correct it by changing https to http, after that it jumps to the anchor as it should. From this exactly same bug you can tell that all the variations of that hack are from the same source.
Not satisfied with code quality ;) and windows popping up when I did not want to, I did my own hack.
With popup and full page commenting the code uses either popup or full page, which ever the blog uses. With embedded comment form text cannot be injected into iframe (from another domain), so separate comment page is opened (not popup). Comment form is prefilled with @ + link to the comment the user is replying to.
How to install
Open blog template html for editing, expand widget templates. Search line that contains:
<data:commentPostedByMsg/>
Just after that paste the following code, but change 12345CHANGETHIS6789 to your blog's id number. You can find your blog id by going to Design, it is in the url: http://www.blogger.com/rearrange?blogID=HEREISYOURBLOGID (old interface) or http://www.blogger.com/blogger.g?blogID=HEREISYOURBLOGID#template (new interface). And here's the code:
Remember, change the blog ID! It is there in the url when you are editing the template, too. Save, and you're done. You can style the CSS class "comment-reply-link", if you like, but it is not necessary. With CSS you can have hover effect for the link etc. You might also want to use an image instead of the [reply] text.
There is one hack with variations circulating in internet which gives you the opportunity to reply to individual comments in Blogger. There are some shortcomings in that code. It always uses a popup and the popup does not position (scroll) to the comment form when opened, this is a bug and annoying if there are many comments. You can correct it by changing https to http, after that it jumps to the anchor as it should. From this exactly same bug you can tell that all the variations of that hack are from the same source.
Not satisfied with code quality ;) and windows popping up when I did not want to, I did my own hack.
With popup and full page commenting the code uses either popup or full page, which ever the blog uses. With embedded comment form text cannot be injected into iframe (from another domain), so separate comment page is opened (not popup). Comment form is prefilled with @ + link to the comment the user is replying to.
How to install
Open blog template html for editing, expand widget templates. Search line that contains:
<data:commentPostedByMsg/>
Just after that paste the following code, but change 12345CHANGETHIS6789 to your blog's id number. You can find your blog id by going to Design, it is in the url: http://www.blogger.com/rearrange?blogID=HEREISYOURBLOGID (old interface) or http://www.blogger.com/blogger.g?blogID=HEREISYOURBLOGID#template (new interface). And here's the code:
Data provided by Pastebin.com - Download Raw
Remember, change the blog ID! It is there in the url when you are editing the template, too. Save, and you're done. You can style the CSS class "comment-reply-link", if you like, but it is not necessary. With CSS you can have hover effect for the link etc. You might also want to use an image instead of the [reply] text.
2
The ultimate hack for broken Blogger navbar search
My first workaround for navbar search was not too shiny: it redirects user to google search with the keywords user entered, search limited to your blog. Works though. But I wanted something better, and finally came up with this hack. For this hack you need custom Google search installed in your blog, see How to add Custom Google Search to your Blogspot blog. You also better have getElementsForClassName installed for better old browser support, and count blogger posts on page hack.
This is quite a long story, so to get you motivated, I'll first show you how it works. With keyword "bedica" the "original" navbar search found nothing from my MS-potilas blog (in Finnish), but with my hack, it looks like this:
Navbar search has had problems since 2009. Also the search gadget is now broken (broke this year). Search gadget can be replaced by custom Google Search, but what about navbar? We certainly don't have access to the code that searches the posts.
So, the (broken) search executes when user tries to use the navbar search, without us having any control. But, we can do things after that, when the results, or no results, are displayed. That is what my hack is based on.
Start with these:
1. Know your way around
2. Install getElementsForClassName function
3. Install Count Blogger Posts on Page hack
4. Install Custom Google Search in your blog. Test that it works.
After successfully completing these steps you have done most of the work already :) Now edit the template html. Find </head>, and before that add:
Save template, then open page elements. Open custom search gadget (HTML/Javascript) you made. In that code change: var customSearchControl = ... to customSearchControl = ... (i.e. remove "var" from that line). Don't alter the rest of the line. Don't add the ellipsis.
Then, after line:
Interesting detail discovered during coding: In Firefox, Chrome and Opera the customSearchControl is created after the before-</body> script is run. In Internet Explorer customSearchControl was created before the script is run. That's why we need the execute function in both places (script & gadget), so we can run it when customSearchControl is created and we have the search keywords. Both are needed, and we cannot be sure, which is set first.
Now when you use navbar search, in the search results first are google results, and after those are, if any, navbar's own findings. If navbar search did not find anything, the "No posts found" text is removed (this needs the post count hack). In this blog the navbar search happens to work pretty good, but I'll install this hack here anyway for demonstration.
Update January 20th 2012: You might be interested in adding a clear results button to the search results, hack here.
Update March 2012: Commented nine (line 24-32) lines from the source, if you had this installed you might want to do the same. By commenting the lines, the new "Sort by date" link is not hidden.
This is quite a long story, so to get you motivated, I'll first show you how it works. With keyword "bedica" the "original" navbar search found nothing from my MS-potilas blog (in Finnish), but with my hack, it looks like this:
Navbar search has had problems since 2009. Also the search gadget is now broken (broke this year). Search gadget can be replaced by custom Google Search, but what about navbar? We certainly don't have access to the code that searches the posts.
So, the (broken) search executes when user tries to use the navbar search, without us having any control. But, we can do things after that, when the results, or no results, are displayed. That is what my hack is based on.
Start with these:
1. Know your way around
2. Install getElementsForClassName function
3. Install Count Blogger Posts on Page hack
4. Install Custom Google Search in your blog. Test that it works.
After successfully completing these steps you have done most of the work already :) Now edit the template html. Find </head>, and before that add:
<script type='text/javascript'> var searchPhrase = ""; var customSearchControl = null; </script>You can also add those two variable definition lines into some existing <script> block there before </head>, if you want. Then, find </body> and before that add:
Data provided by Pastebin.com - Download Raw
Save template, then open page elements. Open custom search gadget (HTML/Javascript) you made. In that code change: var customSearchControl = ... to customSearchControl = ... (i.e. remove "var" from that line). Don't alter the rest of the line. Don't add the ellipsis.
Then, after line:
customSearchControl.draw('cse', options);
add: if(searchPhrase != "")
customSearchControl.execute(searchPhrase);
For a nice finishing touch, let's make the search result links open in the same window. This also applies for the sidebar search gadged, naturally, because we're editing it's code. After line:customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);add:
customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_TOP);After those modifications the code looks something like this (don't copy this code directly, this searches my Finnish blog, no use for you), changed/added lines highlighted:
<div id="cse-search-form" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'fi', style : google.loader.themes.MINIMALIST});
google.setOnLoadCallback(function() {
customSearchControl = new google.search.CustomSearchControl('014531972749200972566:g5b3gu6awfk');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_TOP);
var options = new google.search.DrawOptions();
options.setSearchFormRoot('cse-search-form');
customSearchControl.draw('cse', options);
if(searchPhrase != "")
customSearchControl.execute(searchPhrase);
}, true);
</script>
Save gadget and you're all done.Interesting detail discovered during coding: In Firefox, Chrome and Opera the customSearchControl is created after the before-</body> script is run. In Internet Explorer customSearchControl was created before the script is run. That's why we need the execute function in both places (script & gadget), so we can run it when customSearchControl is created and we have the search keywords. Both are needed, and we cannot be sure, which is set first.
Now when you use navbar search, in the search results first are google results, and after those are, if any, navbar's own findings. If navbar search did not find anything, the "No posts found" text is removed (this needs the post count hack). In this blog the navbar search happens to work pretty good, but I'll install this hack here anyway for demonstration.
Update January 20th 2012: You might be interested in adding a clear results button to the search results, hack here.
Update March 2012: Commented nine (line 24-32) lines from the source, if you had this installed you might want to do the same. By commenting the lines, the new "Sort by date" link is not hidden.
Wednesday, October 5, 2011
29
How to Highlight author comments in Blogger
Update Jan 17th 2012: now uses simpler code.
Update January 18th 2012: A new and easy to install threaded commenting hack version 2 includes this hack's functionality, you might consider using it.
There are some highlight author comments hacks out there, but most I've seen check only that comment author name is something. It is better to check the author url (so anonymous user's won't disquise as you so easily), which my hack does. But it is easiest to use the variable "data:comment.authorClass" – for blog authors it is set to "blog-author", and we can check that. Basically my hack puts all "user comments" into div with class "normal-comment", and "admin comments" into div with class "admin-comment".
Edit your template html. Select Expand Widget Templates. Find line:
Remember to change the url between the "s to your profile page url. In the old code you needed to change the url, in this new code you don't have to change anything. Then find lines:
Update January 18th 2012: A new and easy to install threaded commenting hack version 2 includes this hack's functionality, you might consider using it.
There are some highlight author comments hacks out there, but most I've seen check only that comment author name is something. It is better to check the author url (so anonymous user's won't disquise as you so easily)
Edit your template html. Select Expand Widget Templates. Find line:
<b:loop values='data:post.comments' var='comment'>After that add:
Data provided by Pastebin.com - Download Raw
<b:include data='comment' name='commentDeleteIcon'/>
</span>
</dd>
(you can search using the first line). Just after those lines add:</div>Then save the template. Now we need only to style the admin-comment to look different. Go to Template Designer, choose Advanced, Add CSS, and add following:
.admin-comment {
background: #F4F4F4;
margin-top: 6px;
margin-bottom: 6px;
padding: 3px 3px 0 3px;
border: 1px solid #EDEDED;
}
And then to the testing. You can style admin-comment background otherwise, if you like, using CSS. I have installed this hack on this blog.
Tuesday, October 4, 2011
47
Make "Post a Comment" link bigger
Because of problems with the embedded comment form I decided to change my blogs' commenting use separate comment page. Other option would have been a popup window, which I don't like.
But the Post a Comment link is so small, will people notice it at all? To compare with embedded form:

It looked so small, that I decided to enlarge my link. :)
Here's how I did it. Open template HTML, select Expand Widget Templates. Update 2013: Select "Jump to widget" "Blog1". Search for a block that looks like this:
Now the link is bigger (<H4>) so people will notice it easier. See this article's Post a Comment link here.
But the Post a Comment link is so small, will people notice it at all? To compare with embedded form:

It looked so small, that I decided to enlarge my link. :)
Here's how I did it. Open template HTML
<b:if cond='data:post.allowComments'>
<a expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'><data:postCommentMsg/></a>
</b:if>
And change it to this:Data provided by Pastebin.com - Download Raw
Now the link is bigger (<H4>) so people will notice it easier. See this article's Post a Comment link here.
Labels:
commenting,
hack,
links
Short URLs:
tinyurl.com,
goo.gl,
safe.mn,
v.gd,
cli.gs


Monday, October 3, 2011
0
Workaround for navbar search bug
Navbar search problems have been around since 2009, as known issues blog tells. And still outstanding (as opposed to fixed). This was the first things I noticed when I switched from Wordpress.com to Blogger.
Known issues blog instructs us:
OK, maybe good for blog writers, but what about our users... not very user friendly. My first solution to fix the navbar search was to automate that googling. Here's how it can be done.
Navbar search to Google search
Edit your template html. Insert this code either just before </head> or just before </body>.
You can also customize the code to your liking, for example remove the confirm question, if you know how to. Know your way around.
This was my first solution to the broken navbar search, and it works nicely, and is very simple to install. I used this solution for a while, then came up with something completely different... I'll write about my second navbar workaround later on.
In the meanwhile, because search gadget is also broken, you might consider adding a custom Google search to your blog's sidebar: How to add Custom Google Search to your Blogspot blog.
3.10.2011 Navbar search works actually quite well in this blog (surprise, does not work for my other blog), but I installed this hack here for demonstration. I will remove it when I install the second generation navbar search hack and blog about it.
5.10.2011 This hack is removed, installed The ultimate hack for broken Blogger navbar search
Known issues blog instructs us:
As a workaround, you can use search operators on Google.com to search for content specifically on your blog. For example:
site:yourblog.blogspot.com KEYWORD KEYWORD
OK, maybe good for blog writers, but what about our users... not very user friendly. My first solution to fix the navbar search was to automate that googling. Here's how it can be done.
Navbar search to Google search
Edit your template html. Insert this code either just before </head> or just before </body>.
<script type='text/javascript'>
//<![CDATA[
var blogUrl=window.location.protocol + "//" + window.location.host + "/";
var qPos = window.location.href.indexOf('/search?q='); // length 10
if(window.location.href.indexOf('/search/label/') == -1 && qPos != -1)
{
var urlGoogle = "http://www.google.com/search?q=" + window.location.href.substring(qPos+10) + "+site:" + encodeURIComponent(blogUrl);
if(confirm("Navbar search is broken. Search with Google?"))
window.location = urlGoogle;
}
//]]>
</script>
If you put the code before </head>, the page below won't draw before user is asked to move to google search (the question pops up on white screen). If you put it before </body>, the page loads and then pops up the question, so user can see if the broken search actually found anything. You can test it in both places and choose which ever you like the most.You can also customize the code to your liking, for example remove the confirm question, if you know how to. Know your way around.
This was my first solution to the broken navbar search, and it works nicely, and is very simple to install. I used this solution for a while, then came up with something completely different... I'll write about my second navbar workaround later on.
In the meanwhile, because search gadget is also broken, you might consider adding a custom Google search to your blog's sidebar: How to add Custom Google Search to your Blogspot blog.
3.10.2011 Navbar search works actually quite well in this blog (surprise, does not work for my other blog), but I installed this hack here for demonstration. I will remove it when I install the second generation navbar search hack and blog about it.
5.10.2011 This hack is removed, installed The ultimate hack for broken Blogger navbar search
Sunday, October 2, 2011
1
"# comments" link in index page hack
I changed this blog's commenting to use full page comment form. With embedded form there are problems with cookies across different domains, I could fix them but my readers might not. So I decided to use the only good option: full page. (some might also like popup window, I don't)
With embedded form commenting, when you view articles in index, suppose you have 5 comments in a post, then there is a link 5 comments which opens the post and jumps to comments section (#comments). This is nice.
But with full page comment form the link 5 comments don't open the post and comments, but the commenting page instead. I think it is better to open the post and comments, and there user can click Post Comment link if he wants to post a comment. When there are 0 comments, the link still may open the commenting page directly.
This can be accomplished quite easily. Open you templates html for editing, click Expand Widget Templates. Find code that looks like:
We insert three adjacent things into original code, highlighted red, old code is black (no need to do anything about this snipped, this is just for clarification):
<b:if cond='data:post.allowComments'>
1. <b:if cond='data:post.numComments == 0'>
<a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'><data:post.numComments/> <data:top.commentLabelPlural/></a>
<b:else/>
2. <a class='comment-link' expr:href='data:post.url + "#comments"' expr:onclick='data:post.addCommentOnclick'><b:if cond='data:post.numComments == 1'>1 <data:top.commentLabel/><b:else/><data:post.numComments/> <data:top.commentLabelPlural/></b:if></a>
3. </b:if>
</b:if>
Now it works the way I want. I'll install this hack on this blog, except on this particular post, so you can test it – this post works like it was before, all others work like this hack. Instructions are not too detailed, so you should know your way around before trying to apply to your blog.
References:
Blogger Help: How do I leave comments on a blog?
With embedded form commenting, when you view articles in index, suppose you have 5 comments in a post, then there is a link 5 comments which opens the post and jumps to comments section (#comments). This is nice.
But with full page comment form the link 5 comments don't open the post and comments, but the commenting page instead. I think it is better to open the post and comments, and there user can click Post Comment link if he wants to post a comment. When there are 0 comments, the link still may open the commenting page directly.
This can be accomplished quite easily. Open you templates html for editing, click Expand Widget Templates. Find code that looks like:
<b:if cond='data:post.allowComments'>
<a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'><b:if cond='data:post.numComments == 1'>1 <data:top.commentLabel/><b:else/><data:post.numComments/> <data:top.commentLabelPlural/></b:if></a>
</b:if>
That code should be inside <b:includable id='post' var='post'> block (there's another one for mobile devices, block <b:includable id='mobile-post' var='post'>, that one I didn't touch, you can, if you want). Replace that previous code by:Data provided by Pastebin.com - Download Raw
We insert three adjacent things into original code, highlighted red, old code is black (no need to do anything about this snipped, this is just for clarification):
<b:if cond='data:post.allowComments'>
1. <b:if cond='data:post.numComments == 0'>
<a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'><data:post.numComments/> <data:top.commentLabelPlural/></a>
<b:else/>
2. <a class='comment-link' expr:href='data:post.url + "#comments"' expr:onclick='data:post.addCommentOnclick'><b:if cond='data:post.numComments == 1'>1 <data:top.commentLabel/><b:else/><data:post.numComments/> <data:top.commentLabelPlural/></b:if></a>
3. </b:if>
</b:if>
Now it works the way I want. I'll install this hack on this blog, except on this particular post, so you can test it – this post works like it was before, all others work like this hack. Instructions are not too detailed, so you should know your way around before trying to apply to your blog.
References:
Blogger Help: How do I leave comments on a blog?
Labels:
commenting,
hack,
index,
links
Short URLs:
tinyurl.com,
goo.gl,
safe.mn,
v.gd,
cli.gs


Friday, September 30, 2011
5
Fix Blogger post and page titles
Now that Google finally begun indexing this site, I remembered the page <title>'s. And that they are not to my liking in Blogspot.
Default Blogger page titles are like this:
Imagine those titles in Google search, or better still, on browser tabs or operating system's taskbar. Hard to differentiate one from the other! Better titles would be, at least I think:
Default Blogger page titles are like this:
main page: YourBlogTitleWhichCanBeVeryLongInSomeCases
a page: YourBlogTitleWhichCanBeVeryLongInSomeCases: A Page
a post page: YourBlogTitleWhichCanBeVeryLongInSomeCases: A Post
archive page: YourBlogTitleWhichCanBeVeryLongInSomeCases: September 2011
Imagine those titles in Google search, or better still, on browser tabs or operating system's taskbar. Hard to differentiate one from the other! Better titles would be, at least I think:
main page: YourBlogTitleWhichCanBeVeryLongInSomeCases
a page: A Page | YourBlogTitleWhichCanBeVeryLongInSomeCases
a post page: A Post | YourBlogTitleWhichCanBeVeryLongInSomeCases
archive page: September 2011 | YourBlogTitleWhichCanBeVeryLongInSomeCases
This way the important information is first. Luckily the fix is simple: Edit template html. Find line:
<title><data:blog.pageTitle/></title>
and replace it with:
<b:if cond='data:blog.pageType == "index"'>
<title><data:blog.pageTitle/></title>
<b:else/>
<title><data:blog.pageName/> | <data:blog.title/></title>
</b:if>
Save template and test. Now index-type (index and search) pages keep old titles, others get new titles. You can use other characters instead of | there, and more characters than one, too. If you could not make it, please read know your way around.
1
Remove unnecessary links for older / newer posts in Blogger
This hack was inspired by this discussion thread on Blogger forums. First I made the solution (remove the Show older posts link in the grey box) which I describe in the last post, which is already quite good. But then I developed it further, and now it can remove unnecessary links in label searches almost every time, like 95% or 19/20 (it cannot always know if it is ok to remove the link, and then it does not).
This script uses getElementsByClassName, and some older browsers don't have it, so first install the function to your template using the instructions here.
Then you must install the post count hack. You don't have to set the window title, we'll just use the numPosts variable.
After installing those two, open your template html again, search for </body>, and insert this code before it:
And there it is, many of the unnecessary and even confusing links are now removed in label searches. I'm really no javascript guru and one could possibly check the links some better way, but this works and it is good enough for me. :)
This script uses getElementsByClassName, and some older browsers don't have it, so first install the function to your template using the instructions here.
Then you must install the post count hack. You don't have to set the window title, we'll just use the numPosts variable.
After installing those two, open your template html again, search for </body>, and insert this code before it:
Data provided by Pastebin.com - Download Raw
And there it is, many of the unnecessary and even confusing links are now removed in label searches. I'm really no javascript guru and one could possibly check the links some better way, but this works and it is good enough for me. :)
Labels:
getelementsbyclassname,
hack,
labels,
links,
numposts
Short URLs:
tinyurl.com,
goo.gl,
safe.mn,
v.gd,
cli.gs


Wednesday, September 28, 2011
103
Blogger posts in chronological order, 2011 version
Many bloggers and readers would like to have the option to read the blog, or part of the blog, in chronological order. In Wordpress this is possible and I used it in my blogs, but unfortunately, Blogger does not support this. So we need a hack.
This hack is based on David Merrimans hack, thanks to David for that. But that hack did not work in Internet Explorer, and no longer worked on other browsers either. I first fixed the script for my MS-potilas blog, where I wrote an article about that hack. Now I have rewritten the code, so this is a completely new and better version. It works on new templates (at least on Simple, september 2011) and possibly on old ones, too.
What the script does
The script is placed before </body> tag, so it executes just after the page elements have been constructed. We dig into the DOM model of the page, find the posts, and reverse the viewing order of the posts on that page.
We can make the script reverse the posts on different conditions. For example, I reverse posts when the url contains argument order=ASC (like it worked in Wordpress). I also include the script only for index-type pages (including front page and label searches) using widget tags, so posts and other pages won't have this script.
My script also modifies the previous/next posts links at bottom of the page, adding argument order=ASC there, so user can browse through all the posts, from first to the latest.
Posts in chronological order hack script
Edit your template's html. Find </body> tag, and insert before that this code:
Now, if you view your blog, nothing is changed. But, if you add #order=ASC to the url of your blog, like http://yourblog.blogspot.com/#order=ASC (you must reload page, F5), the posts on the page should be reversed. If not, something went wrong and you probably should also read this.
How to use it - building the link's url
The code version checks, if url contains order=ASC, so we need a link with order=ASC in it. You probably want this link to go to page with your first page. Link's url looks like, for example (in MS-potilas blog), this: http://mspotilas.blogspot.com/search?updated-max=2011-02-14T08%3A08%3A00%2B02%3A00&max-results=7. We add #order=ASC there (& instead of ? because there are arguments already), and the resulting url is http://mspotilas.blogspot.com/search?updated-max=2011-02-14T08%3A08%3A00%2B02%3A00&max-results=7#order=ASC.
You need to modify the red and green parts and possibly the blue parts of the url to get your first post displayed. First change your blog url, that's easy. Then there is updated-max parameter, which contains the date of the first post not shown anymore on the first posts' page + your time zone. And then the number of posts per page, from your blog's settings.
Let's assume you have 7 posts per page. Go to Edit posts, find the 8th oldest post you've written to your blog, and get it's publishing date and time, say for example 2010/06/30 5:14 pm. And your time zone is PST (Pacific time, GMT-7). Here is your url parameters: ?updated-max=2010-06-30T17%3A14%3A00%2D07%3A00&max-results=7#order=ASC
And explained: 5:14 pm must be changed to 24 hour clock, that becomes 17:14. Time zone must be changed to GMT +- #. Plus sign (+) in the time zone encodes to %2B and minus sign (-) encodes to %2D, so the time zone part is %2D07. First two blue 00:s are the seconds of post timestamp. Last two blue 00:s are minutes of timezone, usually 0, but if not, you need to change them.
Test your url. If result goes off by one post, try incrementing/decrementing the minutes value in the url by 1. Test the next/previous posts links at bottom of the page, too.
Gadget for the link
In my MS-potilas blog, I added the link to the right sidebar using HTML/Javascript gadget. Go to Page elements and add HTML/Javascript gadget where you want it. Contents of this widget (you need to change the red part for your blog, see previous chapter, to get to the page with your first post) are:
Link is shown only, if posts are not already shown in chronological order (the if clause). You can change this, if you want. And of course use your own blog's url, and the link text to your liking. If you're completely lost, read know your way around.
Several posts on same day?
Blogger groups all posts with same date to a group, which in the DOM model looks like one big post. The above script cannot reverse order of the posts inside the group. But if you have posts in your blog with same date, the fix is simple, just install my Show date on all Blogger posts within same date hack, and the posts in same day can now be shown in chronological order.
Option: use script on specific url (label, for example)
Because I wanted to give the reader (and me) the option to read posts in chronological order, while preserving the default view's order, I made the script run with the url paramerer order=ASC and gave user the link. Depending on your needs, you may want to run the script on other conditions. For example, when showing posts with a specific label.
In the code before </body> change <b:if cond='data:blog.pageType == "index"'> to <b:if cond='data:blog.url == "http://yourblog.blogspot.com/search/label/yourlabel"'>. Then replace if(window.location.href.indexOf('order=ASC') > -1) { with only {. You can also use other urls between the "'s.
Tested on
Firefox, Opera (on Linux)
Chrome (on Linux and Windows Vista)
Internet Explorer 8 (on Windows Vista)
I will install this hack on this blog, too, so you can see it working and inspect the source codes.
Update Oct 16th 2011: I made another chronological post hack which uses blog feed, you might want to check that out, too.
This hack is based on David Merrimans hack, thanks to David for that. But that hack did not work in Internet Explorer, and no longer worked on other browsers either. I first fixed the script for my MS-potilas blog, where I wrote an article about that hack. Now I have rewritten the code, so this is a completely new and better version. It works on new templates (at least on Simple, september 2011) and possibly on old ones, too.
What the script does
The script is placed before </body> tag, so it executes just after the page elements have been constructed. We dig into the DOM model of the page, find the posts, and reverse the viewing order of the posts on that page.

We can make the script reverse the posts on different conditions. For example, I reverse posts when the url contains argument order=ASC (like it worked in Wordpress). I also include the script only for index-type pages (including front page and label searches) using widget tags, so posts and other pages won't have this script.
My script also modifies the previous/next posts links at bottom of the page, adding argument order=ASC there, so user can browse through all the posts, from first to the latest.
Posts in chronological order hack script
Edit your template's html. Find </body> tag, and insert before that this code:
Data provided by Pastebin.com - Download Raw
Now, if you view your blog, nothing is changed. But, if you add #order=ASC to the url of your blog, like http://yourblog.blogspot.com/#order=ASC (you must reload page, F5), the posts on the page should be reversed. If not, something went wrong and you probably should also read this.
How to use it - building the link's url
The code version checks, if url contains order=ASC, so we need a link with order=ASC in it. You probably want this link to go to page with your first page. Link's url looks like, for example (in MS-potilas blog), this: http://mspotilas.blogspot.com/search?updated-max=2011-02-14T08%3A08%3A00%2B02%3A00&max-results=7. We add #order=ASC there (& instead of ? because there are arguments already), and the resulting url is http://mspotilas.blogspot.com/search?updated-max=2011-02-14T08%3A08%3A00%2B02%3A00&max-results=7#order=ASC.
You need to modify the red and green parts and possibly the blue parts of the url to get your first post displayed. First change your blog url, that's easy. Then there is updated-max parameter, which contains the date of the first post not shown anymore on the first posts' page + your time zone. And then the number of posts per page, from your blog's settings.
Let's assume you have 7 posts per page. Go to Edit posts, find the 8th oldest post you've written to your blog, and get it's publishing date and time, say for example 2010/06/30 5:14 pm. And your time zone is PST (Pacific time, GMT-7). Here is your url parameters: ?updated-max=2010-06-30T17%3A14%3A00%2D07%3A00&max-results=7#order=ASC
And explained: 5:14 pm must be changed to 24 hour clock, that becomes 17:14. Time zone must be changed to GMT +- #. Plus sign (+) in the time zone encodes to %2B and minus sign (-) encodes to %2D, so the time zone part is %2D07. First two blue 00:s are the seconds of post timestamp. Last two blue 00:s are minutes of timezone, usually 0, but if not, you need to change them.
Test your url. If result goes off by one post, try incrementing/decrementing the minutes value in the url by 1. Test the next/previous posts links at bottom of the page, too.
Gadget for the link
In my MS-potilas blog, I added the link to the right sidebar using HTML/Javascript gadget. Go to Page elements and add HTML/Javascript gadget where you want it. Contents of this widget (you need to change the red part for your blog, see previous chapter, to get to the page with your first post) are:
<script type="text/javascript">if(window.location.href.indexOf('order=ASC') == -1) document.write('<a href="/search?updated-max=2011-02-14T08%3A08%3A00%2B02%3A00&max-results=7#order=ASC" title="Show all articles in chronological order"><b>Articles in chronological order</b></a>');</script>
Link is shown only, if posts are not already shown in chronological order (the if clause). You can change this, if you want. And of course use your own blog's url, and the link text to your liking. If you're completely lost, read know your way around.
Several posts on same day?
Blogger groups all posts with same date to a group, which in the DOM model looks like one big post. The above script cannot reverse order of the posts inside the group. But if you have posts in your blog with same date, the fix is simple, just install my Show date on all Blogger posts within same date hack, and the posts in same day can now be shown in chronological order.
Option: use script on specific url (label, for example)
Because I wanted to give the reader (and me) the option to read posts in chronological order, while preserving the default view's order, I made the script run with the url paramerer order=ASC and gave user the link. Depending on your needs, you may want to run the script on other conditions. For example, when showing posts with a specific label.
In the code before </body> change <b:if cond='data:blog.pageType == "index"'> to <b:if cond='data:blog.url == "http://yourblog.blogspot.com/search/label/yourlabel"'>. Then replace if(window.location.href.indexOf('order=ASC') > -1) { with only {. You can also use other urls between the "'s.
Tested on
Firefox, Opera (on Linux)
Chrome (on Linux and Windows Vista)
Internet Explorer 8 (on Windows Vista)
I will install this hack on this blog, too, so you can see it working and inspect the source codes.
Update Oct 16th 2011: I made another chronological post hack which uses blog feed, you might want to check that out, too.
Labels:
chronological order,
hack,
post order
Short URLs:
tinyurl.com,
goo.gl,
safe.mn,
v.gd,
cli.gs


16
"Count" blogger posts on page
In some scripts it is be useful to know the number of posts on a page. It can be used for example to hide the "previous posts" link, I'll write about that some time later. Information about posts and their count is available only in the blog posts widget which shows the posts. First I made javascript function which incremented a counter on each post loop iteration to get the post count, but then I found out that posts widget has a template variable called data:numPosts (not documented), which holds the number of posts displayed on current page. So the code got much simpler, and that's why quotation marks for "count". Here is how you do it.
Declare javascript variable numPosts
This step is not absolutely necessary, but I like to declare the variables used in the whole page. Best place for this is in html head. So, edit template html, find </head> and add this before it:
Ok, for this one you need to edit the html, again, and select Expand Widget Templates. Then find line:
Testing
To test that code works, find </body>, and add before that:
Declare javascript variable numPosts
This step is not absolutely necessary, but I like to declare the variables used in the whole page. Best place for this is in html head. So, edit template html, find </head> and add this before it:
<script type='text/javascript'> var numPosts = 7; </script>Default value is 7 posts per page. If there is already some javascript before </head>, you can also add only the var numPosts = 7; line before the </script> tag. Something like this (highlighted line is added, others are old lines):
// ... some old code here ... // ... some old code here ... var numPosts = 7; //]]> </script>Assign actual numPosts value in the posts widget
Ok, for this one you need to edit the html, again, and select Expand Widget Templates. Then find line:
<b:includable id='main' var='top'>and add after that these lines:
<script type='text/javascript'> numPosts = <data:numPosts/>; </script>And now we have the number of posts showing on the page in javascript variable numPosts.
Testing
To test that code works, find </body>, and add before that:
<script type='text/javascript'> document.title = document.title + " (viewing " + numPosts + " posts)"; </script>Again, if there is already some javascript there, before </body>, you can also add document.title... line there. Now when viewing the blog, window title should be "YourBlogName (viewing # posts), where # is the number of posts on page.
22
Show date on all Blogger posts within same date
Blogger groups articles written on same day together, and the template variable data:post.dateHeader is only set for the first displayed post of the day (which is the last post of the day because of non-chronological blog post order). I saw some instructions to replace dateHeader by timestamp, that is ok but you loose the timestamp under the post. I came up with this solution, tested it, googled a little more, and found that some others had invented similar hacks, too. But here is mine.
These instructions work for the "Simple" template (september 2011), may work for others, too. I will install this hack on this blog to verify, that these instructions work.
Edit your blog's HTML. If you don't know how, you should definitely read this: Know your way around.
Commenting out template lines
Choose Expand Widget Templates. Edit 6/2013: Select Jump to widget -> Blog1 (editor has been changed). Find the section of code (use browser's find function, ctrl+F), where this string is three times:
For me that code section looks like this (it may be different for you):
Add javascript code to copy the date
Stay in the html editor and the vicinity of those previously commented lines. A few lines up from there, look for a line like this:
These instructions work for the "Simple" template (september 2011), may work for others, too. I will install this hack on this blog to verify, that these instructions work.
Edit your blog's HTML. If you don't know how, you should definitely read this: Know your way around.
Commenting out template lines
<b:if cond='data:post.isDateStart'>
For me that code section looks like this (it may be different for you):
<b:if cond='data:post.isDateStart'>
<b:if cond='data:post.isFirstPost == "false"'>
</div></div>
</b:if>
</b:if>
<b:if cond='data:post.isDateStart'>
<div class="date-outer">
</b:if>
<b:if cond='data:post.dateHeader'>
<h2 class='date-header'><span><data:post.dateHeader/></span></h2>
</b:if>
<b:if cond='data:post.isDateStart'>
<div class="date-posts">
</b:if>
The important parts are the tree "if" lines and their corresponding "endif" lines. Put those three <b:if>'s in html comments, and also their closing tags </b:if>'s, like this:<!-- <b:if cond='data:post.isDateStart'> -->
<b:if cond='data:post.isFirstPost == "false"'>
</div></div>
</b:if>
<!-- </b:if> -->
<!-- <b:if cond='data:post.isDateStart'> -->
<div class="date-outer">
<!-- </b:if> -->
<b:if cond='data:post.dateHeader'>
<h2 class='date-header'><span><data:post.dateHeader/></span></h2>
</b:if>
<!-- <b:if cond='data:post.isDateStart'> -->
<div class="date-posts">
<!-- </b:if> -->
This is a good way to "delete" things from your html template. Blogger will strip all comments out, so they won't clutter the final html of your blog page.Add javascript code to copy the date
Stay in the html editor and the vicinity of those previously commented lines. A few lines up from there, look for a line like this:
<div class='blog-posts hfeed'>After that line, add these lines:
<!-- dates for all posts (on same day)/mspotilas. commented if/endif-lines + added unindented lines: --> <script type='text/javascript'> var postDate=""; </script>That section is not absolutely necessary, but I like to declare the variables I use (C/C++ background). Then move down about 16-20 lines, where you should find a lines:
<b:if cond='data:post.dateHeader'>
<h2 class='date-header'><span><data:post.dateHeader/></span></h2>
After those add these lines:
<script type='text/javascript'> postDate = "<data:post.dateHeader/>"; </script> <b:else/> <h2 class='date-header'><span><script type='text/javascript'> document.write(postDate); </script></span></h2>Now you should have date for every post, also on posts written on the same day.
0
Smiley emoticons to Blogger, and getElementsByClassName
This small script changes textual smileys into graphical emoticons in post texts and comments in a Blogspot blog. Before trying to apply this, you should know your way around in html and customizing your blog.
getElementsByClassName
Go to Design -> Edit HTML. Insert this code before </head>-tag:
This function does not exist on some older browsers, so if it doesn't, we define it here. This getElementsByClassName will be used by many other script snippets, too, so it is useful to add, even if you don't add the actual smiley codes, which we do next.
Smileys/emoticons script and css
In html editing, add this code before </body>-tag:
You should upload decent smilies for example to your Picasa albums, and change the smilies' urls accordingly. These smilies are just for demonstration. You can use them to test the script. Smilies, now 6 of them, can be added or removed by modifying the code, the code should be self explanatory. See also Smileys test post.
And finally go to Template designer, Advanced, Add CSS, and copy this css definition there:
There you go. Now find your favorite smileys and upload them to web, and change the script's img urls. :)
getElementsByClassName
Go to Design -> Edit HTML. Insert this code before </head>-tag:
Data provided by Pastebin.com - Download Raw
This function does not exist on some older browsers, so if it doesn't, we define it here. This getElementsByClassName will be used by many other script snippets, too, so it is useful to add, even if you don't add the actual smiley codes, which we do next.
Smileys/emoticons script and css
In html editing, add this code before </body>-tag:
Data provided by Pastebin.com - Download Raw
You should upload decent smilies for example to your Picasa albums, and change the smilies' urls accordingly. These smilies are just for demonstration. You can use them to test the script. Smilies, now 6 of them, can be added or removed by modifying the code, the code should be self explanatory. See also Smileys test post.
And finally go to Template designer, Advanced, Add CSS, and copy this css definition there:
img.emoticon {
border: 0; padding: 0; margin: 0;
-moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none;
}
You may also add the css directly to html instead of using Template designer, if you know what you are doing.There you go. Now find your favorite smileys and upload them to web, and change the script's img urls. :)
Labels:
emoticon,
getelementsbyclassname,
hack,
smileys
Short URLs:
tinyurl.com,
goo.gl,
safe.mn,
v.gd,
cli.gs


Subscribe to:
Posts (Atom)


