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>

84 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

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