Friday, 16 October 2015

General: Alphabetical List of Posts


One thing sorely missing from the features of Google's Blogger is an option to list all the posts of a blog in alphabetical order. That's something essential for a film review blog like mine, in which the posts' titles are the names of films. Yesterday my friend Matt coded this solution for me in Javascript. You can see the results by clicking on the link at the top of this page. (The link is only visible if you are reading the blog on a computer).

I've included the code below. If you wish to use it, copy and paste it into the HTML section of a standalone page.

If you use this code, please leave a comment saying thanks and a link to your blog.



Addendum on 8th May, 2016

Important note: The introduction of mandatory HTTPs support has stopped the code working. I have made a correction to make it work again. If you copied the code before today you need to copy it again.



Addendum on 26th November, 2015

Important note: Yesterday Google made a change which stopped the code working. I have made a correction to make it work again. If you copied the code before today you need to copy it again.



<div>
<ul id="postList12"></ul>
</div>
<script type="text/javascript">
var startIndex = 1;
var maxResults = 150;
var allResults = [];
function sendQuery12()
{
   var scpt = document.createElement("script");
   scpt.src = "/feeds/posts/summary?alt=json&callback=processPostList12&start-index=" + startIndex + "&max-results=" + maxResults;
   document.body.appendChild(scpt);
}

function printArrayResults(root)

   //Sort Alphebetically
   allResults.sort(function(a, b){
        var a_string = a.children[0].textContent ;
        var b_string = b.children[0].textContent ;

 if(a_string < b_string) return -1;
 if(a_string > b_string) return 1;
 return 0;
   })

   var elmt = document.getElementById("postList12");
    for (index = 0; index < allResults.length; index++) {
         elmt.appendChild(allResults[index]);
    }
}

function processPostList12(root)
{   
  var elmt = document.getElementById("postList12");
   if (!elmt)
      return;

   var feed = root.feed;

   if (feed.entry.length > 0)
   {
      for (var i = 0; i < feed.entry.length; i++)
      {
         var entry = feed.entry[i];
         var title = entry.title.$t;
         var date = entry.published.$t
  
         for (var j = 0; j < entry.link.length; j++)
         {
            if (entry.link[j].rel == "alternate")
            {
               var url = entry.link[j].href;
               if (url && url.length > 0 && title && title.length > 0)
               {
                  var liE = document.createElement("li");
                  var a1E = document.createElement("a");
                  a1E.href = url;
                  a1E.textContent = title + " (" + date.substr(0,10) + ")";
                  liE.appendChild(a1E);
                  //elmt.appendChild(liE);
                  allResults.push(liE);
               }
               break;
            }
         }
      }
      if (feed.entry.length >= maxResults)
      {
         startIndex += maxResults;
         sendQuery12();
      } else {
         printArrayResults();
      }
   }
}
sendQuery12();
</script>

116 comments:

  1. Thank you so much! It worked! This was really helpful! I will do a little more customization and I guess it will be good to go.

    Thanks again!!!

    ReplyDelete
    Replies
    1. I'm glad you like it. I wish it had been my personal code, but I'm not a web programmer. If you make any interesting customisation, can you share your new code with me, please? It might be something I want to do as well.

      I moved your comment from the place where you originally posted it. Please leave any follow up comments here, rather than on the list itself. Thanks.

      Delete
    2. Hi Mike,

      It's working again with the new code. Thanks a lot.

      Delete
  2. Excellent. I noticed an old-code that used a yahoo file had stopped working, but this new script worked a treat!

    Linked back to this page so others can find the script.
    Excellent solution for alphabetical listing of titles on your Blogger blog!

    http://houghtonregisheritage.blogspot.co.uk/p/heritage-index.html
    http://adwphotos.blogspot.co.uk/p/photo-index.html

    ReplyDelete
    Replies
    1. I'm glad you can use it, Alan. This code is supposedly better than the old Yahoo Pipes solution, because the Pipes solution only worked for a maximum of 2000 posts (which I'll probably exceed by early 2017), whereas this solution allows for a theoretically unlimited number of posts.

      Delete
  3. I tried the code. Maybe I am not understanding where to put the code because I can't get it to work. You stated " If you wish to use it, copy and paste it into the HTML section of a standalone page." I am not sure what you mean by "standalone page". I am assuming this is a different page on my website. Is this correct? Thank you!

    ReplyDelete
    Replies
    1. Hi. In your blogger overview page, click on Pages. Then click "New Page". Name the new page somethiing like "Alphabetical List". Click on the HTML tab, copy and paste the code into it. Change in blog name in line 11, publish it, and that's all.

      I see you have a custom domain name. I don't have one myself, so I don't know how the interplay is. Do you still have access to the "normal" blogger layout as well as your custom domain? If so, that's where you have to put the code.

      Delete
  4. Those who are using my code have probably noticed that it stopped working yesterday. It was necessary to change the value of the variable maxResults from 500 to 150 to fix it. The corrected code is now shown above.

    ReplyDelete
  5. Replies
    1. You're welcome. I'm glad to meet another film blogger, especially someone who loves horror films! It's a pity I don't understand your language. Bosnian?

      Delete
  6. Thank you very much. I thought I'll never get my alphabetical list back when pipes closed. Until now. Code works fine for me! Thanks a lot!

    Regards,
    Sarah

    ReplyDelete
    Replies
    1. I'm glad to be of assistance. I posted the code on October 16th and thought it would work forever, or at least as long as Blogger exists. Then it stopped working six weeks later. Google changed something in the background. It was easy to alter the code so that it worked again. I hope that the new version (posted on November 26th) will work forever. If your page ever stops working, which I hope it won't, come back to my site and check if there are any updates.

      Delete
  7. Hi, can I remove the date ? I want to display the post title only without the post date. Thank you much.

    ReplyDelete
    Replies
    1. There's a line towards the end:
      a1E.textContent = title + " (" + date.substr(0,10) + ")";
      Change this to
      a1E.textContent = title;

      Delete
  8. Wow!! After months of searching I found this post. Thank you so much. This code works like a charm

    ReplyDelete
    Replies
    1. I'm glad you like it, Golu. I still think Google should offer an "official" alphabetical list of posts option.

      Delete
  9. Excellent work. Thanks. This was also a timely effort given the recent demise of the Pipes alphabetical thingy.

    ReplyDelete
    Replies
    1. You're welcome, Nigel. I'm glad this little bit of code can help so many people.

      Delete
  10. Thank yoy very much for your kindness sharing this tip with us. I have been trying to get a solution for ages and I finally did with your help. Thanks a lot xxx

    ReplyDelete
    Replies
    1. You're welcome, Ana. I'm glad the code is so useful to so many people. What sort of blog do you write? As a film blogger an alphabetical list is essential to me, because it's a list of the films I've reviewed.

      Delete
  11. Hi Dansator, thank you a lot for this helpful code (and to the great programmer that is your friend) and your permission to use it.
    And your page is excellent, too as far I can see.

    ReplyDelete
    Replies
    1. ... forgot the link to mine
      http://indieanajane.blogspot.de/

      Delete
    2. Thanks Jane. I'm glad you like my blog so much. When I started it I only expected it to be read by my friends. For the first 12 months I was only having about 200 pageviews per month, and then it suddenly took off. My record was 11,000 but usually it's about 4000-5000 per month. I just wish that more people would leave comments on my posts. One comment is worth a hundred pageviews to me, because then I know someone has read what I've written and thought about it, rather than just scrolling through and looking at the pics.

      Delete
  12. Thanks a lot for the solution! it worked great!
    http://ro2morpg.blogspot.ro/
    http://mmorpg2try.blogspot.ro/

    ReplyDelete
    Replies
    1. Hi Deliria. I'm glad you can use the code.

      Delete
  13. no loading page
    http://hentaitk.blogspot.pe/p/lista.html

    ReplyDelete
    Replies
    1. Hyung, it looks like there's a script on your page that redirects the page before it loads. That's what it looks like, at least. You need to check for yourself what is preventing the page loading.

      Delete
  14. Oh Nice Code. Its working great. Thank you very much.

    here is my list......

    http://www.teluguthesis.com/p/blog-page_20.html

    ReplyDelete
    Replies
    1. I'm glad I could help you. Happy New Year!

      Delete
  15. Thanks. Had an alphabetic archive that just disappeard. Back in business again thanks to you. http://uddafilm.blogspot.se/

    ReplyDelete
    Replies
    1. I'm glad I could help, Udda. You have an interesting film site. I read a couple of articles with Google's automatic translation service, but the silly translations were too annoying for me to carry on. Congratulations anyway. I love to see people writing about films, especially those that are away from the mainstream.

      Delete
  16. Like you I had previously used Yahoo Pipes, but it stopped working. Today I found the solution through your website, Thanks for sharing!
    Here is my list
    http://www.bhajanlyricsworld.com/p/blog-page_6.html

    ReplyDelete
    Replies
    1. I'm so glad that the code works for you. Please recommend it to your friends. I don't understand why Google doesn't supply this as an inbuilt feature.

      Delete
  17. Hi, is it possible to change the "The"
    Ex: The Allman Brothers Band to, Allman Brothers Band, The?
    Thanks

    ReplyDelete
    Replies
    1. I'm sure it is possible, if you're a programmer. I can't help you, maybe somebody else can.

      Delete
    2. I'm not a programmer.
      If you find someone that knows how to do it please post it. Thanks a lot.

      Delete
  18. When I asked that question I was refering to the Alphabetical Code that is above.

    ReplyDelete
    Replies
    1. Yes, I know what you meant. I can ask about it for you.

      Delete
    2. Here's my blog address http://cs-mm.blogspot.com/

      Delete
  19. Just noticed today that my yahoo pipe code stopped working. Thank you so much for this solution!!

    ReplyDelete
    Replies
    1. Oh, it took you a while to notice! Five months? I use the feature a lot myself on my own blog, almost every day. Whenever I write a new post I check what I've written previously about similar films. The alphabetical list is a lot easier to navigate than the search feature.

      I really hope that someone from Google will find this post. It really ought to be an inbuilt blogger function. If it's advertised on Google's own pages more people would use it. As it is, only relatively few people stumble on this page by accident, and even those who find it might not trust the code. Non-programmers are terrified of viruses and trojans.

      Delete
  20. Hi, the code doesn't work for me anymore, I had to change from 150 to 100, is that happening just for me or everybody?

    ReplyDelete
    Replies
    1. It's still working fine for me with a maxResults value of 150.

      Delete
    2. Hi Mike

      For a while it stopped working for me but I changed back to 150 and now its OK. Thanks

      Delete
  21. Hello! Thanks for this code...but I have a problem: Sometimes the alphabetical post lists disappears from the blog!!! Why? Can you help me?? Thanks...

    ReplyDelete
    Replies
    1. Sorry, I don't understand what you mean.

      Delete
    2. no problem,it seems to work well now...thank you very much :)

      Delete
  22. Hi, mine stopped working since Google had the HTTP to HTTPS update

    ReplyDelete
    Replies
    1. I've received messages about the HTTPS update, but it hasn't been implemented for my blog yet. If I manually turn on the HTTPS the code doesn't work. I'll have to try to get more information about it.

      Delete
    2. Hi Mike,

      I really like this search it was working fine on Dynamic Views until they change the HTTP to HTTPs. If you could fix this would be great. Thanks a lot.

      Delete
    3. I've made a change to the code today. It should work. Please try it and let me know if it works.

      Delete
    4. Hi Mike,

      The new code is working. Thanks a lot

      Delete
    5. The new code is working fine it takes between 5-15 seconds other times longer but opens my 5000+ posts. Thanks again

      Delete
    6. The list was faster when it was possible to read chunks of 500 at a time. Having to decrease the chunk size (maxresults) to 150 halved the speed (for my blog anyway).

      I use your blog as a stress test for my code. As far as I know, no other blog that uses my code has more posts.

      Delete
  23. Oh no!! Sorry but it happened again!! The code doesnt work always, that what I meant...if you go to my website http://thomaspynchonslibbr.blogspot.it/
    there is on the left "post in ord. alfabetico" (posts in alphabetical order); when I copy and paste the code it works but, after hours or days the alphabetical list disappears...why? could you help me? thanks

    ReplyDelete
    Replies
    1. I'm not sure what you're trying to do, Thomas, but it isn't right. The words "post in ord. alfabetico" aren't a link. If you look at my blog in comparison, the words "For a list of all posts in alphabetical order click here" are a link to the page http://dansator.blogspot.com/p/alphabetical-list.html

      You need to copy and paste the code unto a standalone page, and offer visitors a link to that page.

      Delete
    2. ah, my fault!! I inserted the code in a widget html!! Now I have inserted the code in a page html and it works now!!
      thanks a lot mister Hood

      Delete
    3. You're welcome, Thomas. Today I made a small change to the code to make it work on blogs with mandatory HTTPs support. So far this only effects American blogs (blogspot.com) but it will probably be extended to other countries (such as blogspot.it) in the near future.

      Delete
  24. I was informed that the code no longer worked for blogs with mandatory HTTPs support (which hasn't yet been rolled out for all countries). I have made a small change in line 11 of the code to fix the problem. If your list no longer works, please copy the new version of the code.

    ReplyDelete
    Replies
    1. Hi I tried your list yesterday cause we ran into same problem and it stopped working. We ran into the problem over last few days when our list stopped working. Its kind of a big problem since its a large list and a relatively popular site for video game mods.

      Delete
    2. New code does work but it sometimes loads. sometimes doesnt.

      Delete
    3. I don't understand why the code should sometimes work for you. It should either always work or never work. What's your blog address, so I can check it out for myself? How large is your list? My blog has 2025 posts, and I write new posts almost every day. Do you have more posts?

      Delete
  25. Good evening Mr. Hood. I have a big problem with my blog regarding a like dislike and share buttons widget. If you go on my blog: http://recensioni-libri-classici.blogspot.it/
    and open a post you can see these grey buttons: LIKE DISLIKE AND SHARE. But the problem is that these buttons are showed only when we open a post and I' d like that they were showed also IN EACH POST OF THE HOMEPAGE, like the five stars of the star rating widget. I tried to change the html code but when I changed the bif line:
    b:if cond='data:blog.pageType == "item"'
    div id='bi-tip-rating-2546'/
    /b:if
    the only thing I managed to do is showing the buttons IN JUST THE FIRST POST OF THE HOMEPAGE...but I want them to be showed IN ALL POSTS IN THE HOMEPAGE...Mr Hood, because you are an HTML expert, I thought you could help me...I hope so... I took the button widget here: http://www.realcombiz.com/2013/08/how-to-add-like-dislike-and-share.html
    You could follow the instructions and trying it on your blog...Please MR HOOD, help me, I am DESPERATE, I tried to change the html code for days but I can't obtain that the buttons were showed in EACH POST of the HOMEPAGE...Hope you can help me. REGARDS

    ReplyDelete
    Replies
    1. I'm sorry, Thomas, I can't help you with this. I do have some knowledge of HTML, but I don't consider myself an expert. I suggest you post your question in the Google forums, the Blogger section. I've posted questions in the past and always received good advice. The address is http://productforums.google.com

      Delete
  26. Is there an easy way to remove the breaks between titles in the list?

    ReplyDelete
    Replies
    1. When I used the code there was an extra line break between each item.
      Apple

      Banana

      Cherry

      like that. Is there a way to remove the extra breaks between the lines so it looks like this:
      Apple
      Banana
      Cherry

      Delete
    2. There are no extra line breaks when I use the code. What browser are you using? It looks fine for me with Google Chrome and Internet Explorer.

      Delete
  27. Thanks buddy, after yahoo pipes broke my functionality (which I guess has been dead for awhile) your solution works beautifully, hopefully google doesn't keep messing with it

    ReplyDelete
  28. Thanks so much for sharing this code! It is exactly what I was looking for!

    ReplyDelete
  29. Hello. It is possible to have this "List of Posts", list the post by date, with the date appear like date/month/year ?

    ReplyDelete
    Replies
    1. I only have very primitive knowledge of Javascript, so I can't give you a solution. You might have a friend who can help you. All I can say is that the main logic in the code is the alphabetic sorting. If you don't sort the list it's in reverse chronological order, the newest posts first.

      Delete
  30. This is fantastic. Thank you.

    ReplyDelete
  31. I wanted to share that I tried this and it worked. The next piece I'm looking for is how to turn this into a drop down list as well. With that I will be set. Thanks for posting this solution.

    ReplyDelete
  32. Hi Mike,

    My list stopped working for me this morning, could you please check yours to see if there is a problem with it? Thanks

    ReplyDelete
  33. I changed the amount of 150 to 100 and now it is working, could you give me some feedback about this? Thanks

    ReplyDelete
    Replies
    1. Hi Azor. It's still working for me with maxResults = 150. I don't know why you had a problem. However, any value less than 150 will definitely work, so there's no harm in reducing the value to 100.

      Delete
  34. Hi Mike,

    I don't know what happened, but I just changed back to 150 and it is working again.
    I would like to ask you if it is possible to reverse the date to 11-27-2016?
    Thanks for replying.

    ReplyDelete
  35. http://maorisong.blogspot.co.nz/2017/01/a-z.html Cheers!!

    ReplyDelete
    Replies
    1. I'm glad I could be of assistance. Happy New Year!

      Delete
  36. Wow, very nice job. It took me a few days to find your to list my posts. You did it perfectly. It's better than using the labels (no comments box appears when you click on labels that show posts) and it's better than the general blog archive widget. Thanks so much. Kathy www.cosmicclues.com

    ReplyDelete
    Replies
    1. I'm glad the code helps. It's not a replacement for labels. Labels have their use as well. I wish Google would pay attention to users and offer an official alphabetic feature. They can even use my code if they want to :)

      Delete
  37. Hi Mike,

    Yesterday I had a Windows 10 update and since then the list doesn't work anymore. Could you please let me know if I have to change anything to make it back to work. Thanks

    ReplyDelete
    Replies
    1. There's no reason why a Windows update should change anything. The only possibility I see is that there's a change in the security settings on your computer that blocks Javascript.

      Delete
  38. I wrote a comment before telling you that the search code stopped working on my blog, but I don't see the comment here anymore. Could you please check the blog https://cs-mm.blogspot.com and let me know what can be causing to stop. Thanks

    ReplyDelete
    Replies
    1. A few months ago I was forced to introduce comment moderation because of a large amount of spam. Your comments are immediately visible to me, but nobody else can see them until I accept them as genuine. This might take a few hours, depending on whether I'm asleep or at work, but it won't take long.

      What's the exact page of your alphabetical list? I still suspect it's a problem with Javascript settings.

      Delete
  39. Ok, sorry to send you two comments.

    Here is the page where the searches are

    https://cs-mm.blogspot.com/p/main-menu.html. They are under the icon Search +, you have to click on it and hold/drag to the desire search

    Thanks

    ReplyDelete
    Replies
    1. Your page doesn't load at all. Have you changed the URL? For non-existent pages in a blog there's no error because the user is redirected to a default page. The URL you are using is http://cs-mm.blogspot.com/p/downloadable-alphabetical-post-list.html

      Delete
  40. This page doesn't load anymore. It started since yesterday after a Windows 10 update. I didn't change anything to your code at all. I already tried your code in another page and it doesn't load at all, but if I change the 150 to hight will load, but won't show all the posts.. Thanks for all your help

    ReplyDelete
  41. I set up a page called TESTING PAGE in the same menu that the searches are and I changed the var maxResults = 250;, please go and click on that page, it comes up but not all the posts, but at 150 it doesn't show anything, could this be because of 7500 posts that I have?

    ReplyDelete
    Replies
    1. If maxResults is set too high only a small selection of the posts will be shown. I think the problem is caused by your high number of posts. It takes a long time to load all the results. The browser probably abandons the page because the loading time is too long. That's my theory. I'll look into it.

      Delete
  42. Hi Mike,

    I live in Massachusetts, USA and I am using windows 10, I just talked to a friend of mine in Portugal that daily frequents the blog, he uses windows 7 and he told me that he can open the searches very quick. As I told you, everything was fine until the windows 10 update yesterday

    ReplyDelete
    Replies
    1. I use Windows 8, and I can't load your alphabetical list. Try something, please. Can you see MY alphabetical list at http://dansator.blogspot.de/p/alphabetical-list.html ?

      Delete
  43. I just reversed the 7500 post and let 7499 and the search works. So it means that I can't use 7500? Is there any way to fix this? Can you go there and check if it opens? Thanks for your help

    ReplyDelete
    Replies
    1. I just tried it. It works perfectly. I see exactly 7499 posts in your list. There's nothing in the code that should stop it working at 7500 posts. There must be some sort of limit in the Javascript environment. I'll try to find out for you.

      Delete
    2. One more thing: create two more posts and try again. I want to know if it works with 7501 posts.

      Delete
    3. I published two more posts and it works.

      So, from now on it will work when I post?

      Delete
    4. It's a subtle error. I'll try to get it fixed. The page won't load when the number of posts is divisible by 150. It was a cure coincidence that the error showed up at the same time as your update to Windows 10.

      Delete
  44. Yes it was really a coincidence, that's why I thought that was windows update the problem and also the posts that I published add up on 7500.
    This search is a BIG help for me and for a lot of people.
    I will come back here to check if there is a fix
    Thanks again for your help

    ReplyDelete
  45. I'm glad to have found this post. I recently started a blog of everyday family recipes and wanted an alphabetical index. This does the trick perfectly!
    Blog is: Rumble in the tumble

    ReplyDelete
    Replies
    1. You're welcome. I see your blog is relatively new at the moment. When you have a hundred or more recipes together an alphabetical list will be essential. It's best to start soon.

      Delete
  46. Hi Mike,

    I am having a problem, two of my posts don't go to the order that they should go, they stay at the top, couldn't you please let me know why? Thanks
    https://cs-mm.blogspot.com/p/downloadable-alphabetical-post-list.html

    ReplyDelete
    Replies
    1. That's funny. I can't see anything wrong. My only suggestion is that you check the posts to see if you've put a blank at the beginning of the title. If that's not the case I'm stumped.

      Delete
    2. It was the spaces in the beginning.

      Thanks a lot again

      Delete
    3. Ha! I made a good guess. I'm glad it's fixed now.

      Delete
  47. Hi Mike,

    I got a problem, let's see if you can solve it.

    I opened another blog, with a Blooger Standard Template and I am trying to run the alphabetical post list but doesn't show up

    https://gotmusiczone.blogspot.com/

    Thanks

    ReplyDelete
  48. Sorry, forgot to tell you , uou probably can't get in it's private unless I send you an email here's mine in case you want to get in musictrunk@gmail.com

    ReplyDelete
    Replies
    1. I suspect the problem is because it's private. The script isn't recognised as an authorised viewer.

      Delete
  49. Hello. The script works perfect. But can you tell me how I can exclude some few, particular posts NOT to be shown on the list?

    Thanks

    ReplyDelete
    Replies
    1. Hi Sven. As I mentioned above, I'm not the programmer of this code. It was supplied by a friend of mine. If you tell me exactly what posts you want to exclude I can ask him, but I can't guarantee that he'll have time to make the changes.

      Delete

Tick the box "Notify me" to receive notification of replies.