Add Multi-Colored Popular Posts to Blogger

Popular Posts is a widget provided by Blogger that displays the most viewed posts on the blog in the last 7 days, last month and of all time. It has three displaying modes: display title only, display title with image thumbnail or display title along with the posts snippets.

To customize this popular posts widget, we have to add a new variable and some CSS codes to our blogger template. So let's begin:

popular posts widget, blogger gadgets


How to add multi-colored popular posts to Blogger

Step 1. Login to your Blogger Dashboard, go to Design >> Edit HTML

popular posts widget, blogger widgets

Step 2. Select "Expand Widget Templates" (make a backup first)
blogger expand widget templates

Step 3. Search for the following tag:

/* Variable definitions
   ====================

Note: If you can't find it, paste it below the autor information that is usually below this tag (CTRL + F):

 <b:skin><![CDATA[/* 

...and should end up with this symbol:
 
 ----------------------------------------------- */

Step 4. Copy and paste just below/after this tag, the next code:

<Group description="PopularPosts Backgrounds" selector="#PopularPosts1">
<Variable name="PopularPosts.background.color1" description="background color1" type="color" default="#fa4242" value="#ff4c54"/>
<Variable name="PopularPosts.background.color2" description="background color2" type="color" default="#ee6107" value="#ff764c"/>
<Variable name="PopularPosts.background.color3" description="background color3" type="color" default="#f0f" value="#ffde4c"/>
<Variable name="PopularPosts.background.color4" description="background color4" type="color" default="#ff0" value="#c7f25f"/>
<Variable name="PopularPosts.background.color5" description="background color5" type="color" default="#0ff" value="#33c9f7"/>
</Group>

Step 5. Search for the following piece of code:

]]></b:skin>

Step 6. Just above/before it, add this code:

#PopularPosts1 ul{margin:0;padding:5px 0;list-style-type:none}
#PopularPosts1 ul li{position:relative;margin:5px 0;border:0;padding:10px}
#PopularPosts1 ul li:first-child{background:$(PopularPosts.background.color1);width:90%}
#PopularPosts1 ul li:first-child:after{content:"1"}
#PopularPosts1 ul li:first-child + li{background:$(PopularPosts.background.color2);width:85%}
#PopularPosts1 ul li:first-child + li:after{content:"2"}
#PopularPosts1 ul li:first-child + li + li{background:$(PopularPosts.background.color3);width:80%}
#PopularPosts1 ul li:first-child + li + li:after{content:"3"}
#PopularPosts1 ul li:first-child + li + li + li{background:$(PopularPosts.background.color4);width:75%}
#PopularPosts1 ul li:first-child + li + li + li:after{content:"4"}
#PopularPosts1 ul li:first-child + li + li + li + li{background:$(PopularPosts.background.color5);width:70%}
#PopularPosts1 ul li:first-child + li + li + li + li:after{content:"5"}
#PopularPosts1 ul li:first-child:after,#PopularPosts1 ul li:first-child + li:after,#PopularPosts1 ul li:first-child + li + li:after,#PopularPosts1 ul li:first-child + li + li + li:after,#PopularPosts1 ul li:first-child + li + li + li + li:after{position:absolute;top:20px;right:-15px;border-radius:50%;background:#353535;width:30px;height:30px;line-height:1em;text-align:center;font-size:28px;color:#fff}
#PopularPosts1 ul li .item-thumbnail{float:left;border:0;margin-right:10px;background:transparent;padding:0;width:40px;height:40px}
#PopularPosts1 ul li a{font-size:12px;color:#444;text-decoration:none}
#PopularPosts1 ul li a:hover{color:#222;text-decoration:none}

Step 7. Now find the following code:

<b:widget id='PopularPosts1' locked='false' title='Popular Posts' type='PopularPosts'>

Step 8. Delete it until you reach at this tag (delete the </b:widget> also):

</b:widget>

Note: Be very careful when removing it. The entire fragment of code should look like this:

<b:widget id='PopularPosts1' locked='false' title='Popular Posts' type='PopularPosts'>
<b:includable id='main'>
  <b:if cond='data:title'><h2><data:title/></h2></b:if>
  <div class='widget-content popular-posts'>
    <ul>
      <b:loop values='data:posts' var='post'>
      <li>
        <b:if cond='data:showThumbnails == &quot;false&quot;'>
          <b:if cond='data:showSnippets == &quot;false&quot;'>
            <!-- (1) No snippet/thumbnail -->
            <a expr:href='data:post.href'><data:post.title/></a>
          <b:else/>
            <!-- (2) Show only snippets -->
            <div class='item-title'><a expr:href='data:post.href'><data:post.title/></a></div>
            <div class='item-snippet'><data:post.snippet/></div>
          </b:if>
        <b:else/>
          <b:if cond='data:showSnippets == &quot;false&quot;'>
            <!-- (3) Show only thumbnails -->
            <div class='item-thumbnail-only'>
              <b:if cond='data:post.thumbnail'>
                <div class='item-thumbnail'>
                  <a expr:href='data:post.href' target='_blank'>
                    <img alt='' border='0' expr:height='data:thumbnailSize' expr:src='data:post.thumbnail' expr:width='data:thumbnailSize'/>
                  </a>
                </div>
              </b:if>
              <div class='item-title'><a expr:href='data:post.href'><data:post.title/></a></div>
            </div>
            <div style='clear: both;'/>
          <b:else/>
            <!-- (4) Show snippets and thumbnails -->
            <div class='item-content'>
              <b:if cond='data:post.thumbnail'>
                <div class='item-thumbnail'>
                  <a expr:href='data:post.href' target='_blank'>
                    <img alt='' border='0' expr:height='data:thumbnailSize' expr:src='data:post.thumbnail' expr:width='data:thumbnailSize'/>
                  </a>
                </div>
              </b:if>
              <div class='item-title'><a expr:href='data:post.href'><data:post.title/></a></div>
              <div class='item-snippet'><data:post.snippet/></div>
            </div>
            <div style='clear: both;'/>
          </b:if>
        </b:if>
      </li>
      </b:loop>
    </ul>
    <b:include name='quickedit'/>
  </div>
</b:includable>
</b:widget>

Step 9. After you have deleted the above code, paste the following in its place:

<b:widget id='PopularPosts1' locked='false' title='Popular Posts' type='PopularPosts'>
<b:includable id='main'>
   <b:if cond='data:title'>
    <h2><data:title/></h2>
   </b:if>
   <div class='widget-content popular-posts'>
    <ul>
     <b:loop values='data:posts' var='post'>
      <li>
       <b:if cond='data:showThumbnails == &quot;false&quot;'>
        <b:if cond='data:showSnippets == &quot;false&quot;'>
         <a expr:href='data:post.href' expr:title='data:post.title' rel='bookmark'><data:post.title/></a>
        <b:else/>
         <a expr:href='data:post.href' expr:title='data:post.snippet' rel='bookmark'><data:post.title/></a>
        </b:if>
       <b:else/>
        <b:if cond='data:showSnippets == &quot;false&quot;'>
         <b:if cond='data:post.thumbnail'>
          <img class='item-thumbnail' expr:alt='data:post.title' expr:src='data:post.thumbnail'/>
         <b:else/>
          <img alt='no image' class='item-thumbnail' src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXyA9OmaunVp-24Qp0U0fU5FOoRFJAkxMKIMsgcgeGWBNM3_dY06dAQpKEDiXGGS6uSI7RTXdiMMR_FWH3lZARyMW-zBwBRR5FGYA5r3VbCoCOwhO_zAGGNc3JdMGQ4OVvdzOjPS-amFU/s1600/default.jpg'/>
         </b:if>
         <a expr:href='data:post.href' expr:title='data:post.title' rel='bookmark'><data:post.title/></a>
         <div class='clear'/>
        <b:else/>
         <b:if cond='data:post.thumbnail'>
          <img class='item-thumbnail' expr:alt='data:post.title' expr:src='data:post.thumbnail'/>
         <b:else/>
          <img alt='no image' class='item-thumbnail' src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXyA9OmaunVp-24Qp0U0fU5FOoRFJAkxMKIMsgcgeGWBNM3_dY06dAQpKEDiXGGS6uSI7RTXdiMMR_FWH3lZARyMW-zBwBRR5FGYA5r3VbCoCOwhO_zAGGNc3JdMGQ4OVvdzOjPS-amFU/s1600/default.jpg'/>
         </b:if>
         <a expr:href='data:post.href' expr:title='data:post.snippet' rel='bookmark'><data:post.title/></a>
         <div class='clear'/>
        </b:if>
       </b:if>
      </li>
     </b:loop>
    </ul>
   </div>
  </b:includable>
</b:widget>

Step 10. Save template.

Settings

- Go back to Layout  and click on the edit link of Popular Posts widget.

Select to "display up to 5 posts", then Save the widget.


- You can easily change the background color of the popular posts widget, going to Template >> Customize  >> Advanced >> PopularPostsBackground and there you can select any color you want.

Blogger blog


You're done!

If you are enjoying reading this blog, please like & subscribe for more tutorials.
For any questions or suggestions, leave a comment below.

Comments/disqusion
33 comments

  1. says:

    Nice blog, def my favourite. Thanks for help!

  2. says:

    Yeah 100% Great Blog... I've learned something too.....

  3. says:

    doesn't display very well on my home pages but it display well in post pages why?

  4. says:

    Thank you, very nice-looking widget

  5. says:

    Help me, i can't find this code .. why ?

  6. says:

    Hi Laurie, please tell me what code you can't find and i'll try to help you. Thanks for visiting!

  7. says:

    hi

    i cannot find the /* Variable definitions

    i have already checked the "expand widget templates"

    please help. tq

  8. says:

    You are awesome..every single thing worked.

  9. says:

    Hi everything worked great! Just can't seem to change the colors? I can change it in the Template Designer but it doesn't actually change in the blog. Any reason?

  10. says:

    Yes same questions, Please help! It looks like a rainbow on steroids. Love the shades of grey on yours!

  11. says:

    Hi Chelsey,

    Sorry for the late answer. You have to press the "Apply to blog" button, have you did so?

  12. says:

    Hey Jessica,

    You have to save the changes by pressing the "Apply to blog" button on the right corner. If it doesn't work, please write me back. Thanks!

  13. says:

    Then you have to paste it under blogger template description which is usually after <![CDATA[/* and it ends with and astericks and a slash (*/)

    Sorry for the late answer!

  14. says:

    Hi, it didn't work :( It also doesn't show the 'edit' tools in the corner... Any other suggestion?

  15. says:

    when i've already followed all the steps, i use Preview to make sure it is safe. but it display error 500.

  16. says:

    CAN I SHARE THIS ON MY BLOG??????

  17. says:

    thanks a lot!

  18. says:

    The same happened to me. I tried to paste the codes below and after the searched ones, but it doesn't matter.

  19. says:

    Not Working :( hmm...

  20. says:

    Hi, i need some help here..i stuck at step 5, i couldnt find the below code,



    please help me, i really love this widget! :(

  21. says:

    finally something to try about. i use this script and match perfectly with my blog template.

  22. says:

    wonderful...i loved it !! thanks :)

  23. says:

    Error parsing XML, line 3094, column 3: The element type "b:widget" must be terminated by the matching end-tag "".
    I have added the gdget as you instructed but i have faced with this problem.......

  24. says:

    Half of my background disappeared! I can't find the code that is causing this...help?

  25. says:

    what if i find /* Variable definitions,where do i put the code?

  26. says:

    Bingo...it worked,you're a star..thank you sooooooo much

    here is my blog,have a look http://clicksomemore.blogspot.com/

  27. says:

    Works fine for my another blogspot blog. Thanks

  28. says:

    first of all plz admin tell me where can i find expand widget template?
    there is no option of it in my blog!

  29. says:

    Same here, colours don't work! I can change them, but they stay white. Neither original code colours show up! Do I really have to have troubles with every single code I try to install???

  30. says:

    It worked perfectly!

  31. says:

    Thank You Very Much

  32. says:

    Hi there!!!

    nice tips you got here, I aplied this particular, but seems that backgrounds for mobile devices are removed somehow... quite weird, the normal version of the blog works normally though.

    Do you have any tip for fixing that issue?
    Thanks in advance, and for this great blog!

  33. says:

    love u