Wednesday, July 02, 2008

How to add Star-rating to Custom Blogger Templates

·

Blogger in draft recently launched couple of updates, fixes and two most sought features to Blogger in draft:

  • Embedding Comment form in each post.
  • Adding Star rating to individual posts.
To read about the complete list of updates and fixes, read this post on Blogger in draft blog.

Now to embed comment form for custom blogger themes and modified templates, Amanda on Blogger Buster has written an excellent how to.
To add Star rating to these kind of custom theme enabled blogs, I couldn't find any trick.  But I sort of played with the code and came up with a solution which should work with any custom built blogger template. 

Step 1:  Backup your existing template.  I assume you know it very well so I am not gonna explain it again.
Step 2:  Expand widget templates and copy the entire code some where in Notepad or something.  In case something goes wrong, you have the entire widget code.
*Step 3:  Go to 'Layouts' and under 'Blog post' widget, select Star rating.  And save the changes.

*Step 4:  Go to 'Edit HTML' and select 'Expand widget templates'.
Step 5:  Search for this line of code:
<p><data:post.body/></p>
Step 6:  Copy the following code right after the above line of code:
<span class='star-ratings'>
        <b:if cond='data:top.showStars'>
           <div expr:g:background-color='data:backgroundColor' expr:g:text-color='data:textColor' expr:g:url='data:post.absoluteUrl' g:height='42' g:type='RatingPanel' g:width='180'/>
        </b:if>
      </span>
Step 7:  Now again search for following code:
<b:include name='feedLinks'/>
This line you may find several times, so make sure you seek for the last instance at the bottom of the code which should ideally be before the start of sidebar codes.  So when you see this line, it should look something like:
<b:include name='feedLinks'/>
  </div>
            </div>
        <div class='cont-bottom'/>
        </div>
        </div>
        </div>
 </b:includable>
</b:widget>
</b:section>
....
....
<div id='sidebars'>
Step 8:  Copy the following code right after the line mentioned above: 
<b:if cond='data:top.showStars'>
    <script src='http://www.google.com/jsapi' type='text/javascript'/>
    <script type='text/javascript'>
      google.load(&quot;annotations&quot;, &quot;1&quot;);
      function initialize() {
        google.annotations.setApplicationId(<data:top.blogspotReviews/>);
        google.annotations.createAll();
        google.annotations.fetch();
      }
      google.setOnLoadCallback(initialize);
    </script>
  </b:if>
Step 9:  Preview your changes without saving it.  You should see the star rating in each post on your blog posts on the main page itself.
Step 10:  That's it, save your template if satisfied and enjoy the Star ratings on your blog.

Also let me know if this post helped you in customising your template by dropping a comment here or at least leaving your rating.

*Update :  Added Steps 3 & 4.  Added image for clarity.


59 comments:

António Amorim said...

Hi Anurag! Thanks for your help! I have a little problem! When I firstly installed the star ratting e got like a white box around the widget. After that Aneesh came with a solution: "Use this sort of code ..."

But still I get the SR background with the colour I want but around the the SR i get a withe box! So I decreased the dimensions of "...g:height='42' g:type='RatingPanel' g:width='180'/>..." and it's perfect in firefox! But in IE7 it's a mess! What I can do? Can I change the code for that white "frame" that appears on both browsers? (Sorry for my english, I'm Portuguese =)

Thaks for the help!

Anurag Bansal said...

Hi Antonio,
I suggest that you check the template to see if the background, foreground and other variables are defined separately in the very starting of the code or not.
If not, try adding the code for those variables from some default blogger template. Just copy and paste.
Then go to Font color tab and change the background color to match it with your theme.
Other thing, don't change anything in the code for SR, it might become unstable if you change something which you are not sure of.
If you can't find the code I mentioned yourself. Let me know your email id, I will send you through mail as comment form won't allow me to paste it so simply and it is a pretty big code.
Hope it helps and you get what you wanted.
Thanks
Anurag Bansal

Cush said...

Hi- can you tell me how to remove the bif lines. When i do it, is says i need to close the div....i am not sure where??? I have followed amandas directions for adding star rating.
Thanks

António Amorim said...

Thanks Anurag! I will try it... thanks

Anurag Bansal said...

@Cush:
Check where the code is ending, just close the code by writing </div> after that line. Preview the changes and you should be all set.
Save the template if satisfied.
Hope it helps.

AN7ONYO said...

I think I tried almost everything! Can you help me? I'll send trough email my template if you want! Send me one to an7onyo@hotmail.com! Thank you sooo much for the help!! :)

Anurag Bansal said...

@An7onyo:
Send me your template, I will see how much I can help.

AN7ONYO said...

Thank anurag! I emailed you at blog@knowliz.com!

Anurag Bansal said...

@An7onyo:
I have sent you the updated template and replied to your mail.
Check if it works. Hopefully it should work, unless there is something really wrong with your template.

Thanks
Anurag Bansal

&lt; naga &gt; said...

Hello, I have tried everything I possibly can, but its just that my blogger template (Hemingway) is completely different. I am emailing you my template, so when you're free could you please look at it?

Really appreciate it. Thank you.

Anurag Bansal said...

@naga:

I got your mail. I am working on it. Let me see how much I can help you.

Thanks
Anurag Bansal

Anurag Bansal said...

@Naga:
I have sent you a mail with updated template. Check if that works.

Thanks
Anurag Bansal

&lt; naga &gt; said...

Its working!! Thank you so much!!

p/s: I just swapped the background and text color to fit in with my blog.

dion said...

It took me awhile to figure out why there are 2 star ratings appearing at the end of my blog posts after i followed your instructions. I figured out that my template already had the 2nd set of codes.
Thanks a lot... great job!

jitendra said...

Hey, Jitendra from SezWho here...The look and feel should be good now...let me know if you still have issues. Thanks, Jitendra

Anurag Bansal said...

Thanks a lot.
It works perfect.

Sezwho rocks!!!

radiofc said...

excellent. thanks!

beta-u said...

thanx its working for me...

Sra said...

This is great! But I'm getting two sets of Star ratings showing up on my page. Any idea why?

Bunsnip.com

Anurag Bansal said...

@Sra:
Check your template after expanding the widgets, you should have two sets of star-rating code somewhere.
If you can't find, send me your full template in xml format. I will look.

Thanks
Anurag Bansal

Anurag Bansal said...

@Sra,
I have sent you the updated template. In fact I could find two sets of code there.
Check, I am pretty sure you shouldn't see two star ratings now.

Thanks
Anurag Bansal

Tapan said...

Anurag,
1. I could not find "show star ratings" in configure blog posts widgets.
2. I could not find "popen data:post.body pclose"
3.
I followed directions from http://www.bloggerbuster.com/2008/07/how-to-add-star-ratings-to-your-blogger.html

That did not work either.

Anurag Bansal said...

@Tapan:
That might be because of two reasons:
1. You are not using the Layout Enabled template.
2. And if yes, you are not checking the 'Widget Templates' under 'Edit HTML'

Let me know if you are able to figure out now.
To use the layout feature, you need to go to Templates -> Select New Template -> Upgrade template. That will give you the latest feature enabled Blogger template.
Hope it helps.

Thanks
Anurag Bansal

Vivek Barun said...

thanks a ton man . i've tried this from so many sources and finally it worked.

ಕವನ said...

thanks! got the ratings running, though I had the two sets of ratings problem too until I deleted the existing code.

MIRELA said...

i know a more simple step to add star ratings in blog,im from Romania so plss enter in my blog page to see how. www.blog-sau-store.blogspot.com
Ijust begin to edit an blog like yours and i found some interestings things...ill write my friends about your blog too:)...nice day

Silverleaf Shiny Stuff said...

Hi there, I'm using a custom template and can't find the code you mentioned at all.

Any changes I make to my blog post configuration don't show up at all.

Any idea what I can do? I'd really like to be able to make changes to the configuration, and add stars.

A Bisht said...

Hi Anurag,

I tried the blogbuster method for my 3 col 867 template. But the method failed. Then on Amanda's recommendation I came here, and the solution you gave worked on the very first attempt. As I maintain a cricket cartoon blog, which is becoming popular with each passing day; the rating system had become inevitable.
Thanks for your guidance. The visir to your blog solved one of my head-aches.

best wishes

A Bisht

A Bisht said...

One thing Anurag, I wear glasses and the black blog background seemed too taxing to my eyes; Has other specs wearers also opined so?

Anurag Bansal said...

Here you go - ABisht..
On your demand I have changed the background to White with Black text.
Let me know if you like it or not.
If you have any other suggestion. Feel free to drop a comment or mail me.
Knowliz is there for readers like you and if readers don't like the black background, then be it so.
Thanks for the suggestion.

Matt said...

Hi I followed your tutorial.

It adds the star rating but get the following error msg in the right hand side bar

"TEMPLATE ERROR: Invalid data reference top.showStars: com.google.layouts.framework.widgetview.GoogleMarkupException: No dictionary named: 'top' in: ['blog']"

Any ideas

Anurag Bansal said...

@Matt:
Can you share your full template with me and a link to your blog so that I can check what kind of issue you might be facing.
Also, please check if you have checked the star rating check-box in Blog post widget.

Cheers
Anurag Bansal

Matt said...

Thanks Anurag.

I've e-mailed you at blog@knowliz.com.

Cheers,

Matt

Khatia said...

thank you for writing about it. Problem is I can't find < b :include name= 'feedLinks' / >

Do you know what would be the reason? and what can I do?

Anurag Bansal said...

@Khatia,
You may send the full template to me, I can check.
Thanks

Jason Law said...

I wonder why after following the instruction, nothing appears... Anyone has the same problem like mine? Have tried several times still failed..

Hope to get helped by the pros ><...

Anonymous said...

Can you pls tell me why there is no star ratings in my blog post widgets? Thanks.

Anonymous said...

Thanks alot! Works like a charm!

Judy Scooter said...

Hello Anurag:
I've tried copying your code several times but can't seem to get it to work. There may be other issues because my blog is heavily customized. Woould you be kind enough to look at my code? I would be most grateful. Many thanks/JudyScooter

Anurag Bansal said...

Go ahead, send me the full template.
I will have a look.
or if possible give me permission on your blog so that I can see it after modification. Then you revoke permission later.

Anything is fine.

Let me know.
Cheers
Anurag Bansal

Judy Scooter said...

Thanks so much. I've added anurag@knowliz.com to the permissions list. If this doesn't work, please let me know the right way to do it. Thanks again.

Anurag Bansal said...

Hi Judy,
Can you please add blog [at] knowliz.com to the permission list.
Thanks
Anurag Bansal

JudyScooter said...

Done!!

Anurag Bansal said...

@Judy:
You need to give me admin access, else I don't get access to layout tab. Don't worry, you can believe me, I guess.

Thanks

Judy Scooter said...

Admin access has been granted. Thanks again for making this effort, Anurag.

Judy Scooter said...

Hi Anurag:
I just noticed that the star ratings are appearing on the link pages--that is, when you click the headline and go to the jump page. But they aren't appearing on the home/post page.
Thanks/Judy

Anurag Bansal said...

@Judy:
I think you should reduce the number of post shown on your blog front page. Looks like you are showing 300 posts which is way too many to show. IMHO, at the max you should show 5 to 10, depending on the length of the post.
That's why your blog takes 10 minutes to load fully and the entire system just hangs for that much time.
Meanwhile I have reduced that while I am working on it. If you want you can increase it later again. Sorry, I can't wait that much to see the changes everytime.

Hope you agree with me.
Thanks
Anurag

Anurag Bansal said...

@Judy:
You are all set. Check it, you should see the Star-ratings on your blog home page and individual post pages.
Let me know if you have any issue.
If you are satisfied, then you can revoke permission from your blog.

Enjoy...
Anurag Bansal

Brad Farless said...

I'm having trouble with getting the white background around the stars.

I'm using the Rounders theme. I added the extra column and widened the main post column using a guide, but none of it is really "third party" per se.

I searched the top variables and I see a mainBGColor, but that's set to FFFFFF for the white background of the posts I think. There is no "backgroundColor." I checked my test site, which is using the default rounders theme, and I don't see it there either. I tried adding a variable for "backgroundColor" but that didn't work either.

What should I replace "data: backgroundColor" with to get this to blend into the background of the post footer?

Help!

http://bradleyf81.blogspot.com

Anurag Bansal said...

@Brad Farless:
I checked your blog and it seems you are showing the blog rating in the bottom footer of every post.
Wouldn't it be good to show in line with the 'Bookmark' widget? You wouldn't have to worry about background color.
Else you need to check the color of your footer. If you want you can send me the full template of your blog. I can look and let you know where you need to change, what.

Hope it helps.

Cheers
Anurag Bansal

Brad Farless said...

How would I do that? Have them show up next to each other? Or rather, one on top of the other, centered would be nice. I tried, but the stars seem a little skewed to the left. I'll send you my template so you can take a look.

Brad Farless said...

Or you could tell me how to change the background color in that footer section?

Anurag Bansal said...

@Brad:
I sent you the updated template. Check if it works the way you wanted.

Thanks
Anurag Bansal

Gerard Banhidi said...

Hi Anurag,

I simply cannot enable posting comments in my Blog. Could you please edit my template?

I will send you an e-mail.

Thanks in advance.

Mohit said...

Hi Anurag!

Could you help me to change the white background color of Star Rating System. The white background doesn't match with the theme. My blog address is http://testingnook.blogspot.com

Thanks in Advance.

Anurag Bansal said...

@Mohit:
Currently there is no way of matching 'Star Rating' Background with the template. It indeed, looks ugly on a dark background blog.
Sorry, I can't help with that.
Instead if you want, you can try a Google Friend Connect widget for ratings. That seems to work well. Let me know if you need help with that.

Cheers
Anurag Bansal

Mohit said...

Thanks anurag for your help and time :) I think I should remove the ratings for now...I will add it in future when I have followers for my blog :)

my_passion48@yahoo.com said...

hi anurag please help its not working for me. i am sending my XML template to you on blog@knowliz.com please check it if there any problem.

Regards
inder

Anonymous said...

hi anurag try this 1 Click setup to get stars.
http://templates-widgets-softwares.blogspot.com/2009/07/add-star-ratings-widget-to-your-blog.html

Post a Comment

Enjoyed this post. You may leave a comment here with your suggestion and feedback.

Search this blog

Loading...

Sponsors

About Knowliz


Knowliz is a technology oriented personal blog. Anurag Bansal is the sole owner, editor and author of this blog.
About the Blog:
Knowliz as a domain was created keeping "KNOWLEDGE" in mind and how it is pronounced. One of the readers of this blog, however, provided a nice acronym for it.

KNOWLIZ = KNOWledge of technology In Life Is priZe less.

Content:
This blog covers vast variety of subjects including but not limited to Computer, Internet, Apple iPhone, Apps, Blogging, Social Networking, Ubuntu, Linux, Open Source, File Sharing and Tips & tricks on various topics. You may, however, find some article on various other lighter topics as well.
Know more about Knowliz on this about page.

Blog Advertising - Advertise on blogs with SponsoredReviews.com

Translate

DISQUS Comments

About the Author

My Photo
ANURAG BANSAL
Plymouth, Michigan, United States
A seasoned technology evangelist, passionate about emerging technologies through internet with experience across engineering, product development, product management, global delivery model & product life cycle management. Strong passion for blogging and innovation with an affinity for public speaking and product evangelism. I am a Mechanical Engineer by profession working for a well renowned Multinational Company based in India. To know more about me and this blog, read the About page...
View my complete profile

Connect with Author

My Zimbio The Ubuntu Counter Project - user number # 20905

Disclaimer and Copyright

Creative Commons License
This work by Anurag Bansal is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
Any review and opinion provided in this blog is unbiased and unpaid. The reviews of those sites, softwares and other content is just for the sole purpose of creating awareness and providing knowledge to readers and fellow bloggers. Any article which is paid in some manner will be specifically mentioned as a paid content or labeled so. If you feel there is something which is biased, then drop me a mail, I will be glad to discuss with you.
Copyright (c) 2008 - 2010 Knowliz - All Right Reserved by Anurag Bansal
This site is best viewed in Mozilla Firefox.