Creating A Random Blogroll Widget In Blogger

I was talking with Sarah a while back about Better Blogroll and she asked whether I knew of a similar widget for Blogspot users that would show a random subset of links from a Blogspot blogroll. Today, I finally spent a little time putting something together that would work within Blogspot’s unique framework. While I didn’t come up with anything that has as many options as Better Blogroll, I did manage to come up with a hack that will allow Blogger users to display a random subset of links from the Blogger Links Widget.

This is a hack, so you’re going to have to get a little dirty to make it work. In the end, you’ll have a random blogroll, but the widget will ignore the “number of items to show” and “sort” options in the widget because those will be controlled from within the new code.

If you’re interested in creating a random links list on your own Blogger/Blogspot blog, read on for the complete instructions.

How To Show Random Links On Your Blogspot Blog

  1. Go to the Layout Tab and click Add Page Element.
  2. Find Links List and click Add To Blog.
  3. Type in a title and click Save Changes.
  4. Go to the top of the Layout page and click Edit HTML
  5. Click Download Full Template, so that if you mess this up, you’ll have a backup of your template.
  6. Put a check in the checkbox that reads Expand Widget Templates.
  7. Search for the line in the template that contains the title you input. It should look something like this:
    <b:widget id='LinkList1' locked='false' title='MyListTitle' type='LinkList'>

    This is the start of the widget you created. Don’t touch this line, but delete all the lines below it until you reach </b:widget>. This is the end of the link list widget. Now you have an empty links widget. Your code should look something like this:

  8. <b:widget id='LinkList1' locked='false' title='MyListTitle' type='LinkList'>
    
    <--NEW CODE WILL GO HERE-->
    
    </b:widget>
  9. What you’ve done is gutted the Links widget, and now you’re going to fill the space with the new random blogroll guts. Take the following code and insert it into the section above that reads “NEW CODE WILL GO HERE”. Please don’t make me tell you that “<--NEW CODE WILL GO HERE-->” should NOT be in your code. You knew that already.
  10. <b:includable id='main'>
    <b:if cond='data:title'><h2><data:title/></h2></b:if>
     <div class='widget-content'>
      <ul>
      <script type='text/javascript'>
      var maxlinks = 10;
      var linksarray = new Array();
      var linksarray2 = new Array();
      <b:loop values='data:links' var='link'>
        linksarray.push(&quot;<a expr:href='data:link.target'><data:link.name/></a>&quot;); 
      </b:loop>
      if (maxlinks&gt;linksarray.length){maxlinks=linksarray.length;}
      for (var i=1;i&lt;=maxlinks;i++)
      {
        linknum = Math.floor(Math.random()*linksarray.length); 
        linksarray2.push(linksarray[linknum]);
        linksarray.splice(linknum,1);
      } 
      for (x in linksarray2.sort())
      {
        document.write(&#39;<li>&#39;+ linksarray2[x] + &#39;</li>&#39;);
      }
      </script>
      </ul>
      <b:include name='quickedit'/>
     </div>
    </b:includable>
    
  11. Well, Dr. Frankenblogger, you’re almost there. The widget defaults to 10 random links. If you want to change that, change the number on this line: var maxlinks = 10; to the number of links that you’d prefer.
  12. Click Save Template.
  13. Click on the Layout Tab.
  14. Click Edit on the Links Widget and add some links to your blogroll.

As always, if you run into problems implementing this, let me know.

Share, Bookmark, or E-Mail This Article

8 Responses to “Creating A Random Blogroll Widget In Blogger”

  1. sarah Says:

    I can’t wait to try this!

  2. Sarah Says:

    Thanks for working that code out!!!

    I tried it and it totally works and is soooo easy to use!!!

    It is awesome sauce!!! Thank you!!!

  3. Jeypriey Says:

    i’m gonna try this one..tnx for the tweak! I really need this .. :)

  4. patrick Says:

    The code for the widget is not showing up.. The place where it says.. “place the following code..” There is no code..

    Hmm..

  5. Jon Says:

    Sorry. Little caching problem. The code should be there now.

  6. TD Says:

    Hey, If you take a look at the blogroll on my site, you will see a bit of weird code for the first random blog. Any idea how to fix this?

    Otherwise, the code seems to function well and is certainly the best way to keep track of a blogroll.

    Thanks.

  7. Trisha Says:

    I just tried to use this and get this error: “Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
    XML error message: The element type “b:includable” must be terminated by the matching end-tag ”

    I tried to use close tags to “b: includable” and received the same error again.

  8. troy Says:

    this is exactly what i was looking for and worked for me perfectly.

Leave a Reply

RSS Comment Feed for This Entry | Trackback URL


Close
E-mail It