LATEST STORIES

Showing posts with label Widgets. Show all posts
Showing posts with label Widgets. Show all posts

Show IP Address & Geolocation Of Website Visitors Via JavaScript

Privacy and freedom are two things no one can compromise for anything. From anonymous web browsing using VPN or proxy servers to anonymous electronic transactions via cryptocurrencies, online freedom is the biggest quest of internet users today.

show IP address using javascript

Achieving complete anonymity online is difficult but not impossible thanks to developers working hard to introduce new tools and apps every other day. I am sure you all know how to hide your IP address using a VPN server, Tor browser or any proxy server but what may seem more appealing to you would be understanding how can you find out your website visitor’s IP addresses and geolocation using plain client-side JavaScript and HTTP API.

More

Christmas Pop-up with Countdown Timer and Falling Snow For Websites

jQuery Christmas pop-up for websitesWelcome your website visitors with falling snow and a count down timer this Christmas 2017. An easy to add jQuery pop-up for Christmas greetings that can be added to any simple webpage, WordPress blog or Blogger blog.

To keep our tradition alive, we are releasing our premium set of jQuery Pop-ups as Holiday gift to all MBT readers. This Popup plugin is specially designed and developed with Five Unique Features! It is completely customizable, has a countdown timer that can be set to any date and time, has 3 different animations, 2 attractive Christmas Background themes and most importantly it is the first popup plugin of its kind introduced for blogger blogs that comes with HTML5 sessionStorage functionality to set cookie in order to control the popup display. You can decide whether to show the popup only once to your visitors or on every new visit. It is perfectly compatible with all major browsers. Interesting part of it is that the scripts are stored on our servers so no headache  on your part thus making the installation extremely easy. You can add it easily to your blogger blog or Wordpress blog or on any webpage you may have. Lets view a Live demo first on Blogger and then on two simple webpages.

More

Create a Christmas Countdown Timer Widget In BlogSpot

christmas countdown widget Add a Christmas count down timer widget to your blogger blog to welcome your blog visitors and wish them happy Christmas. This countdown timer widget counts down to 25 December 2017 and in military time format by counting days, hours, minutes and seconds left for the coming Christmas event. It also alerts and wishes Christmas by generating a pop-up once the count down ends. The JavaScript is provided by dynamic drive and it is customized and enhanced by MBT. This widget will be shared on each event here may it be EID, Holi or New Year. I hope you find it useful. It is extremely easy to install and customize it. The best thing about it is that it contains no ads because we are utilizing a free script provided by dynamic drive and storing it on blogger. Lets get to work then!

More

Text Resizer For Blogger: Resize Font Size in Blog Posts

image
I came across an excellent jQuery based text resizer script for blogger blogs that lets your visitors to change or resize font size of the text in your blog posts. This decreases or increases the text size providing your visitors with better readability. Its useful especially to those with weak eye sights and for those with display issues. Fluid Text Resizer widget has been designed by mybloggertricks and script is adopted from dynamic drive. It will appear just below your post titles and will allow your visitors to toggle the text size to their comfort. Text size on your entire blog will be zoomed in and zoomed out. From sidebars till footer, all text will be maximized. It also includes a Reset link that toggles the default font level. Lets get to work then!

It can adjust the text size of a particular section of your blogger blog, such as just the primary content area or comment section, or the entire document in general.

More

How to Add Social Media Buttons to Blogger Posts? - Top/Bottom Location

In this tutorial you will learn how to add social sharing buttons to each of your blogger posts. These responsive social sharing buttons will stick to the top or bottom of every blog post. It helps your blog visitors to share your content on social media networks without leaving your blog page.

add social media buttons to blogger posts

This sharing gadget for blogspot blogs is a lightweight version of JumboShare Counter. I will thus call it JumboShare Simplified. It loads faster and takes up negligible load time. Load time is a major SEO factor and Google will rank you higher in SERPs only if your webpage loads faster and provides a user friendly interface.

More

Create Table Of Contents (TOC) With Multi-level List In JavaScript

Ever wondered to generate a dynamic Table of Contents list in pure JavaScript without using a single line of jQuery? We have successfully programmed a robust TOC Script in JavaScript and CSS3 entitled as "TOC Plugin V 2.0". This plugin will create a multi-level Table of Contents from a webpage's heading tags on page load in a fraction of a second!

TOC Plugin - Table of contents build in JavaScript

DEMO: The list bellow is dynamically created on page load using this TOC Script.

Introduction To TOC Plugin V 2.0

TOC Plugin V 2.0 is the upgraded version of the TOC Script we released last week. It is much more dynamic in its  functionalities and features compared to the previous one. It is a unique script that auto-generates a TOC from the heading tags (i.e. H1, H2, H3, H4, H5, H6) of the page and adds anchor links to each nested list item.

I recommend the previous version for those bloggers who do not write in-depth content with heading tags of the lower level i.e. (h3,h4,h5). But if you do use multi-level subheadings in your content then V2.0 best suits you.  This new version supports both a flat list or multi-level list of heading tags.

Why Use a TOC?

For webmasters and bloggers who write lengthy articles and divide the article in several sub-sections, the readers may find it difficult reading such long posts without a friendly navigation. The only solution to better present long, lengthy articles is displaying a "Table Of Contents."

TOC is one such feature that you often see on Wikipedia pages to provide easy navigation for long Articles. Wikipedia loves adding a TOC because it helps the readers to jump from one section to another easily.

Is TOC Plugin SEO Friendly?

A TOC gives a basic summary to search engines of what your article is all about. The anchor links inside a TOC offers an added benefit to your SEO efforts. Google loves anchor links and especially when these links are meaningful and provide better navigation and understanding of your blog content.

The contents list generated using TOC plugin is SEO friendly. Anchor links inside it are easily crawled and indexed by search robots. See the image below taken from our last blog post:

JavaScript "Table of Contents" is SEO friendly

Update: TOC V2.0 Anchor links are instantly indexed and crawled by Google minutes after we published this post! :)

Table of contents anchor links indexed by Google

TOC Plugin is must to have if you are serious about ranking high in SERPs.

Features of TOC Plugin

This new version has some additional features as listed below:

  • Coded in pure JavaScript
  • Supports Nested heading tags
  • Numbered Navigation With Counters
  • Finds Heading tags from H2-H6 automatically
  • Adds unique ID to each content section automatically
  • Adds unique ID to each list of anchor links inside TOC 
  • Supports both Flat list & Multilevel List
  • Show/Hide Option
  • Compressed Script
  • Lightweight and fast.
  • SEO Friendly
  • Easily Customized
  • Mobile responsive
  • Executes only when invoked!

How Does It Work?

Optional: You may skip this section if you are not interested in understanding the programming logic used to build this plugin. Click here to go straight to the installation guide.

I have shared the compressed script in the installation section for performance purpose but to give you a more clear idea of how the script gets the list of heading tags and how it converts them into anchor links, please read the detailed explanation below.

Methods Used

The backbone of this entire script is based on using a string search() method with RegExp.

I started by using the getElementById() method to search for all heading tags located inside the DOM having ID "post-toc".

To search for the heading tags <h2>, <h3>, <h3> etc.  I coined a search pattern as explained below.

Using JavaScript Regular Expressions

A regular expression, as you may know is a sequence of characters that forms a search pattern. To search for heading tags, we will need to first create a RegExp or search pattern.

In HTML a heading title will have the following structure:

<h2>Your Sub Heading Text</h2>

Where <h2> is the opening tag and </h2> is the closing tag. This headline tag could also contain attributes or nested tags such as:

<h2 id="xyz">Your Sub Heading Text With a <a href="#">Hyperlink</a></h2>  

In order to perform a perfect search I came up with the following search pattern after many trials and errors.

/<h([\d]).*?>(.*?)<\/h([\d]).*?>/gi

The pattern above is divided into three important groups as discussed below:

1st Group: ([\d])

  • \d matches a digit (equal to [0-9]) (Matches the opening tag)

2nd Group: (.*?)

  • .*? matches any character between opening and closing tags.

3rd Group: ([\d])

  • \d matches again a digit or single character (equal to [0-9]) (Matches the closing tag)

Other matches

  • <h matches the characters <h literally (case insensitive)
  • .*? matches any character (except for line terminators)
  • > matches the character > literally (case insensitive)
  • < matches the character < literally
  • \/ matches the character / literally
  • h matches the character h literally

Global pattern flags

  • g modifier: global. All matches (don't return after first match)
  • i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])

This expression is then passed to replace() function as a search argument.

Using String replace() Method

Once a match is found, the replace method passes these three groups as values to a function with four parameters.

.replace(/<h([\d]).*?>(.*?)<\/h([\d]).*?>/gi,function(Newheading,opening,Title,closing)

I hope the colors may better help you in understanding how the RegExp groups refer to which parameter.

The function takes these values and performs these tasks:

  • It first checks if opening tag is equal to closing tag. If it is the function will continue running else it will exit.
  • It will compare the opening tag integer value against the item level.
  • The TOC displays the list in multi-levels where each level represents the hierarchy.  For example H2 is set to be at level 1, H3 at level 2, H4 at level 3, and so on.
  • If opening tag is greater than the level, then start the array list by appending <ol>  at its beginning.
  • Else If opening tag is less than the level, then close the array list by appending </ol></li> at its end.
  • Assign a unique ID to each Heading and return it back as Newheading.
  • The replace() method then replaces the old heading on page with Newheading containing the unique ID.
  • The array lists are added inside the variable mbtTOC which is then appended inside the DOM mbtTOC2 using innerHTML()
  • The function is invoked only when mbtTOC2() is called.

Programming The CSS Counters

The final part was styling the numbered list, assigning a unique index number to each list item. The default look of the TOC ordered list without CSS styling looks like this:

table of contents with multi levels

Which of course does not build a nested relationship between the link at all and is not a good UI.

However after assigning different CSS classes to each ordered list, I was able to transform the look of TOC to something more user friendly:

.point2 {list-style-type:lower-alpha} 
.point3 {list-style-type:lower-roman} 
.point4 {list-style-type:disc}

table of contents with multiple levels

The alpha-numeric and Roman values does help in better understanding the relationship between parent and child items. But what if you want only numbers? Something exactly similar to wikipedia TOC? For that CSS counters came in handy!

I came across CSS counters few years back when I introduced a numbered threaded comments system for blogger blogs.

Nested Numbering Of List Items

CSS counters are simple "variables" maintained by CSS whose values can be incremented by CSS rules.

For CSS counters the following properties are used:

  • counter-reset - Creates or resets a counter
  • counter-increment - Increments a counter value
  • content - Inserts generated content
  • counter()function - Adds the value of a counter to an element

Using all these available properties I crafted the following styles:

.mbtTOC2 ol{counter-reset:section1;list-style:none}
.mbtTOC2 ol ol{counter-reset:section2}
.mbtTOC2 ol ol ol{counter-reset:section3}
.mbtTOC2 ol ol ol ol{counter-reset:section4}
.mbtTOC2 ol ol ol ol ol{counter-reset:section5}
.mbtTOC2 li:before{content:counter(section1);counter-increment:section1;position:relative;padding:0 8px 0 0;font-size:18px}
.mbtTOC2 li li:before{content:counter(section1) "." counter(section2);counter-increment:section2;font-size:14px}
.mbtTOC2 li li li:before{content:counter(section1) "."counter(section2) "." counter(section3);counter-increment:section3}
.mbtTOC2 li li li li:before{content:counter(section1) "."counter(section2) "."counter(section3) "." counter(section4);counter-increment:section4}
.mbtTOC2 li li li li li:before{content:counter(section1) "."counter(section2) "."counter(section3) "." counter(section4)"." counter(section5);counter-increment:section5}

Where section1, section2, section3 etc. represents CSS counters for the different list levels. In other words they represent the heading tags from H2-H5. I concatenated a counter with its sub-counter in order to create the nested numbered list appearance. (i.e. 1 > 1.1, 1.2 > 1.2.1 and 1.2.1 > 1.2.1.1)

The result was a beautiful interface with nested numbered list as shown below:

table of contents with nested numbered list

Showing and Hiding The ToC

In version two, I replaced the FontAwesome toggle Icon with a Show/Hide toggle link. The function mbtToggle2() first checks the current TOC state, and then generates a new text and a new display style based on that information.

Show/hide button in "Table of contents"

It is called whenever the user clicks on the Show or Hide link, thus making it easy to toggle the content.

Installation Guide

TOC Plugin can easily be installed on any platform. Whether it is a wordpress site, blogspot blog or a simple HTML page. The installation guide consists of three main steps:

  1. Add the JS script and CSS code above </head> tag
  2. Enclose the content section with ID "post-toc"
  3. Add the container Div and the calling function to the page where you wish to display the TOC.

For simplicity, I will discuss the installation steps for blogger blogs only. You can get an idea from these steps in order to integrate the plugin on your 3rd-party CMS platforms.

Add a 'Table Of Contents' In Blogger Posts & Pages

Most blogspot users refer to this plugin as a Table Of Contents widget while in fact it is just a script that needs to be added inside the template and post editor. So using the word widget would be incorrect here, so lets just call it a TOC plugin in short.

Follow these easy steps:

  1. Sign in Blogger > Template
  2. Backup your template
  3. Click "Edit HTML"
  4. Just above </head> tag paste the following source links:
    <link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'/>
    <script type='text/javascript'> 
    //<![CDATA[ 
    //*************TOC Plugin V2.0 by MyBloggerTricks.com 
    function mbtTOC2(){var a=1,b=0,c="";document.getElementById("post-toc").innerHTML=document.getElementById("post-toc").innerHTML.replace(/<h([\d]).*?>(.*?)<\/h([\d]).*?>/gi,function(d,e,f,g){return e!=g?d:(e>a?c+=new Array(e-a+1).join("<ol class='point"+a+"'>"):e<a&&(c+=new Array(a-e+1).join("</ol></li>")),b+=1,c+='<li><a href="#point'+b+'">'+f+"</a>",a=parseInt(e),"<h"+e+" id='point"+b+"'>"+f+"</h"+g+">")}),a&&(c+=new Array(a+1).join("</ol>")),document.getElementById("mbtTOC2").innerHTML+=c}function mbtToggle2(){var a=document.getElementById("mbtTOC2"),b=document.getElementById("Tog");"none"===a.style.display?(a.style.display="block",b.innerHTML="hide"):(a.style.display="none",b.innerHTML="show")} 
    //]]> 
    </script>
        
  5. Next search ]]></b:skin> and just above it paste the following CSS code:
    /*####TOC Plugin V2.0 by MyBloggerTricks####*/
    .mbtTOC2{border:5px solid #f7f0b8;box-shadow:1px 1px 0 #EDE396;background-color:#FFFFE0;color:#707037;line-height:1.4em;margin:30px auto;padding:20px 30px 20px 10px; font-family:Oswald, arial;display: block;width: 70%;}.mbtTOC2 button{background:#FFFFE0; font-family:oswald, arial; font-size:22px;position:relative; outline:none;border:none; color:#707037;padding:0 0 0 15px;}.mbtTOC2 button a {color:#0080ff; padding:0px 2px;cursor:pointer;} 
    .mbtTOC2 button a:hover{ text-decoration:underline; } 
    .mbtTOC2 button span {font-size:15px; margin:0px 10px; }
    
    .mbtTOC2 li{margin:10px 0;  } 
    .mbtTOC2 li a {color:#0080ff; text-decoration:none; font-size:18px; text-transform:capitalize;} 
    .mbtTOC2 li a:hover {text-decoration: underline;}.mbtTOC2 li li {margin:4px 0px;} 
    .mbtTOC2 li li a{ color:#289728; font-size:15px;}
    
    .mbtTOC2 ol{counter-reset:section1;list-style:none}
    .mbtTOC2 ol ol{counter-reset:section2}
    .mbtTOC2 ol ol ol{counter-reset:section3}
    .mbtTOC2 ol ol ol ol{counter-reset:section4}
    .mbtTOC2 ol ol ol ol ol{counter-reset:section5}
    .mbtTOC2 li:before{content:counter(section1);counter-increment:section1;position:relative;padding:0 8px 0 0;font-size:18px}
    .mbtTOC2 li li:before{content:counter(section1) "." counter(section2);counter-increment:section2;font-size:14px}
    .mbtTOC2 li li li:before{content:counter(section1) "."counter(section2) "." counter(section3);counter-increment:section3}
    .mbtTOC2 li li li li:before{content:counter(section1) "."counter(section2) "."counter(section3) "." counter(section4);counter-increment:section4}
    .mbtTOC2 li li li li li:before{content:counter(section1) "."counter(section2) "."counter(section3) "." counter(section4)"." counter(section5);counter-increment:section5}
    /* 
    .point2 {list-style-type:lower-alpha} 
    .point3 {list-style-type:lower-roman} 
    .point4 {list-style-type:disc} 
    */
        

    Make these custom changes if you want:

    • To change background color of container box edit #FFFFE0
    • To change border color of the box edit #f7f0b8
    • To change font color of the headline text edit #707037
    • To change anchor link color edit #0080ff
    • To change link hover color edit #289728
    • If you would like to show the alpha-numeric & roman list style then delete the green highlighted chunk of code and also the two yellow highlighted lines. This will remove the nested numbered list and replace it with alpha-numeric.
  6. Finally search for <data:post.body/> and replace it with the code below:

    Note: You will find this code two or more times inside your template, so replace all its instances with the code below especially the second occurrence. TOC Plugin will not work if you replace <data:post.body/>  just once.

    <div id="post-toc"><data:post.body/></div>
  7. Save your template and you are all done!

How To Show TOC Inside a Post or Page?

Add TOC to only those blog posts which are long and lengthy in length with several subheadings. Adding it to a blog post with just three or less headings does not make sense.

You can add a dynamic TOC inside a blog post in two easy steps.

Step #1 Mention Location Of TOC Container

It is best to display TOC right after your starting paragraph or show it before the first heading on your blog post.

To do this, switch to "HTML" mode of blogger editor and then paste the following HTML code just before the first heading.

<div class="mbtTOC2"> 
<button>Contents <span>[<a onclick="mbtToggle2()"  id="Tog">hide</a>]</span></button> 
<div id="mbtTOC2"></div> 
</div>

 

Step #2  Call The TOC Function

Finally, its time to invoke the plugin so that it could auto-generate a TOC on page load,

To do this, paste the following JS code at the bottom of your blogger editor where your post ends:

<script>mbtTOC2();</script>

Publish your post and see it in action! :)

Copyrights

Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

© 2008-2017 MyBloggerTricks.com
Version: 2.0  2017/02/27

TOC Plugin by MyBloggerTricks (MBT) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

You are most welcomed to share the plugin with your readership as long as you attach credit link back to this page. You are most welcomed to use the plugin in your commercial products as long as you keep the source credits intact.

Feedback

Would love to hear your thoughts on this major upgrade. Let me know if it lived up to your expectations. :)

I tried my best to create an SEO friendly and extremely lightweight script to the best of my ability. I hope it may add a new soul to your content and give it a big push in SERPs.  Share it with your friends and #JavaScript lovers!

Let me know if you need any help or further clarification with any part of this tutorial. Would love to help as soon as time allows.

More

Create Automatic Table Of Contents In JavaScript - TOC Plugin

Wikipedia loves adding an automatic Table Of Contents list for each article it publishes because it engages readers more by providing more accessibility and better navigation. Google prefers high-quality content which is well organized and formatted. Adding elements like tables, numbered sections, and an auto-generated TOC is a big bonus for ranking high in SERPS.

Update: TOC Plugin Version 2.0 has been released.  More advanced with more features!

TOC Plugin: Automatic Table of Contents using JavaScript

In this article, we will share a lightweight TOC plugin written in pure JavaScript to generate an automatic table of contents from the section headings of a web page. 

DEMO: The contents table bellow is dynamically created on page load using this TOC Script.

    What is Table Of Contents or TOC?

    In websites, a table of contents abbreviated as TOC or ToC, is a link list, usually found on a web page placed right after the first paragraph. Each anchor link inside a TOC takes you to a specific section of the web page.

    An HTML TOC provides a quick way to jump to the desired section of a page. It usually includes the titles of the first-level headers (headings) or second level headers(subheadings).

    Table Of Contents of a wikipedia page

    In printable work, a TOC refers to the index page of the book which contains the page number to each chapter. TOC for books are more in-depth and comprehensive, containing not only section titles but descriptions, author names, and subheadings.

    table of contents of a drawing book

    What Is TOC Plugin?

    TOC plugin developed by MBT, is an automatic solution to the tedious method of creating a table of contents manually for each web page. It auto-generates a user-friendly TOC for your lengthy blog articles. It is coded in pure JavaScript and loads lightening fast. Contents table generated using TOC plugin is easily crawled and indexed by search robots.

    • Read this interesting article by MOZ which mentions SEO support for all JS methods that we have used so far in building TOC plugin.

    SEO ALERT: Just minutes after this post was published. Google not only indexed the TOC  anchor Links but also added a "Jump to" label to identify that it is an anchor link that jumps to a particular section. See it to believe it. :)

     Table of contents anchor links indexed by Google

    I have not included lower level heading tags (i.e. h3/h4/h5/h6) in TOC plugin because a blog post is neither a wiki nor a long lengthy book, it is best to show only major headlines for simplicity and accessibility. Adding subheadings or lower levels inside a TOC list only makes it longer in length thus pushing down your main content and destroying visibility.

    Automatic Table Of Contents for blogger blogs

    So far many developers have written a dynamic ToC script but most of these scripts are either coded in jQuery or they are render-blocking JS eating up your page load time. You may even find TOC generator but these scripts again lack flexibility and ease of customization.

    TOC should be added only to those articles which are lengthy or contain at least four headings. On contrary, some TOC generators will add the list on all your pages whether containing several headings or just a single heading, which of course is not a sensible thing to do.

    jQuery table of contents is much slower compared to this plugin built with traditional pure JS. JavaScript is executed much faster by browsers compared to a JS library (jQuery) that needs to be imported first.

    Features of TOC Plugin:

    It is the first JavaScript plugin of its kind that is unique in several ways as mentioned below:

    • Coded in pure JavaScript - just 10 lines of code!
    • Lightweight and fast.
    • SEO Friendly
    • Adds unique ID to each section automatically.
    • Creates both ordered or unordered list
    • Contains a Toggle button
    • Show on any location you choose
    • Easily Customized
    • Mobile responsive
    • Executes only when invoked!

    Pseudo Code Of TOC Plugin

    Understand how the TOC Script works in plain English. The numbered list below is the pseudo code for our TOC plugin. It is a simplified description of the JavaScript code we wrote.

    Table Of Contents for blogspot blogs

    1. Create a function to print headline links
    2. Count the number of heading sections on a page
    3. Run a loop equivalent to the number of heading sections
    4. Extract text content from the heading titles
    5. Give each heading a different ID
    6. Convert the heading text into an anchor link
    7. Print the heading anchor links inside a bullet list
    8. Find the location by TOC ID to display the list
    9. End the loop
    10. Trigger the function only when invoked inside the page

    Table Of Contents with show/hide button

    Following is the pseudo code for the toggle button which shows or hides the TOC.

    1. Create a new function to show/hide the TOC.
    2. Show the TOC by default
    3. Use a conditional statement to check if TOC is hidden or visible.
    4. Use CSS to show or hide the TOC
    5. Trigger the function only when button is clicked

    How To Install TOC Plugin in Blogger Blogs?

    I am sharing below the method of adding TOC plugin in Blogspot blogs but you can apply almost the exact same method for installing this plugin on any website you want, may it be hosted on Wordpress or anywhere else.

    Follow these steps to install it in BlogSpot:

    1. Sign in Blogger > Template
    2. Backup your template
    3. Click "Edit HTML"
    4. Just above </head> tag paste the following source links:
             

      <link href='http://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css' rel='stylesheet'/>
      <link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'/>

      <script type='text/javascript'>
      //<![CDATA[

      //*************TOC plugin by MyBloggerTricks.com
      function mbtTOC() {var mbtTOC=i=headlength=gethead=0;
      headlength = document.getElementById("post-toc").getElementsByTagName("h2").length;for (i = 0; i < headlength; i++)
      {gethead = document.getElementById("post-toc").getElementsByTagName("h2")[i].textContent;document.getElementById("post-toc").getElementsByTagName("h2")[i].setAttribute("id", "point"+i);mbtTOC = "<li><a href='#point"+i+"'>"+gethead+"</a></li>";document.getElementById("mbtTOC").innerHTML += mbtTOC;}}function mbtToggle() {var mbt = document.getElementById('mbtTOC');if (mbt .style.display === 'none') {mbt .style.display = 'block';} else {mbt .style.display = 'none';}}
      //]]>
      </script>

      Note that I am adding source links to Oswald font and Font-Awesome for styling purposes. You may or may not wish to add them. The code inside purple highlighted lines is the major TOC script in no more than 10 lines!

      Make this change only if needed:

      The major heading tag in blogger is H2 but if you are selecting the subheading tag in blogger editor then your default tag would be H3. If you are using the subheading tag as your main heading in your blog posts then please replace h2 with h3 thrice in the code above.  TOC plugin will not work if your heading tag is not correct.

    5. Next search ]]></b:skin> and just above it paste the following CSS code:
            

      /*####Automatic TOC Plugin by MyBloggerTricks####*/
      .mbtTOC{border:5px solid #f7f0b8;box-shadow:1px 1px 0 #EDE396;background-color:#FFFFE0;color:#707037;line-height:1.4em;margin:30px auto;padding:20px 30px 20px 10px; font-family:oswald, arial;display: block;width: 70%;}
      .mbtTOC ol,.mbtTOC ul {margin:0;padding:0;}
      .mbtTOC ul {list-style:none;}
      .mbtTOC ol li,.mbtTOC ul li {padding:15px 0 0; margin:0 0 0 30px;font-size:15px;}
      .mbtTOC a{color:#0080ff;text-decoration:none;}
      .mbtTOC a:hover{text-decoration:underline; }

      .mbtTOC button{background:#FFFFE0; font-family:oswald, arial; font-size:20px;position:relative; outline:none;cursor:pointer; border:none; color:#707037;padding:0 0 0 15px;}
      .mbtTOC button:after{content: "\f0dc"; font-family:FontAwesome; position:relative; left:10px; font-size:20px;}

      Make these color changes if you want:

      • To change background color of TOC box edit #FFFFE0
      • To change border color of TOC box edit #f7f0b8
      • To change font color of TOC headline text edit #707037
      • To change anchor link color edit #0080ff
      • To change font size of anchor links edit 15px
      • To change font size of TOC headline text edit 20px
    6. Finally search for <data:post.body/> and replace it with the code below:

      Note: You will find two or more occurrences of this code so replace all its instances with the code below. TOC Plugin will not work if you replace <data:post.body/>  just once.

      <div id="post-toc"><data:post.body/></div>
    7. Save your template and you are all done!

    Show Table Of Contents Automatically in Blog Posts

    Each time you may want to display TOC inside a specific post, follow these two steps.

    Step #1  Mention Location Of TOC Container

    It is best to display TOC right after your starting paragraph or show it before the first heading on your blog post.

    To do this, switch to "HTML" mode of blogger editor and then paste the following HTML code just before the first heading or anywhere else you may want.

    <div class="mbtTOC"> 
        <button onclick="mbtToggle()">Contents</button> 
        <ol id="mbtTOC"></ol> 
        </div>
    
    • You can replace the text "Contents" with any other text you may like.
    • If in case your headings already contain numbers in beginning then replace ol with ul.

    Add Table Of Contents automatically in blog posts

    Step #2    Activate TOC Plugin

    Finally, its time to invoke the plugin so that it could auto-generate a TOC on page load,

    To do this, paste the following JS code at the bottom of your blogger editor where your post ends:

    <script>mbtTOC();</script>
    

    Invoke TOC plugin

    Publish your post and see the magic! :)

    TOC Plugin Copyrights

    Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

    © 2008-2017 MyBloggerTricks.com
    Version: 1.0  2017/02/14

    TOC Plugin by MyBloggerTricks (MBT) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

    You are most welcomed to share the plugin with your readership as long as you attach attribution link back to this page. You are most welcomed to use the plugin in your commercial products as long as you keep the source credits intact.

    Need Help With TOC Plugin?

    I tried my best making this tutorial as easy as possible but if there is anything you could not understand then please feel free to post your queries below in the comment section. I would love to answer as soon as possible.

    I hope it adds a positive impact on your SERPS ranking and help you in making your content more search-friendly. I will develop the plugin with time, adding more features and functionalities if required. Till then, I would love to hear your feedback on this.  :)

    More

    Breaking News Ticker Widget For Blogger - JSON Feeds Support!

    Breaking News Ticker Widget For blogger

    Breaking News widget for Blogger blogs is a free, flat, stylish, modern, easy to use and responsive Blogger jQuery news ticker. It displays text-based titles of your latest posts in a scrolling fashion automatically. It is the best way to showcase your hottest content to your website visitors on your homepage just how BBC or CNN does it! We have coded it using Blogger JSON Feeds API and jQuery News Ticker plugin.

    UPDATE: Check Headline News Ticker With ToolTips!

    Some sites like codecanyon are selling News Ticker Plugins at $5, but you will not only get it free at MBT but you will also learn how such widgets are coded if you read our JSON Feeds series.

    More

    Create Random Post Slider Widget For BlogSpot Blogs!

    Create Random Post Slider For Blogspot blogsEver wondered you could display images randomly inside a blogger slider? So far we have shared dynamic recent posts slider and a static slider, today for the first time online, we are releasing a Random Post Slider for BlogSpot blogs which is built using Blogger JSON Feeds API, FlexSlider and jQuery. A fully responsive image slider that will automatically display your random posts on your homepage or sidebar, almost anywhere you want.  Lets learn how to create a random slider for blogspot in simple steps but before that lets see a live demo!

    What is Blogger Random Post Slider Widget?

    Due to the natural structure of blogging platforms such as blogspot, articles end up being buried down once they get old. New users often avoid navigating through all your labels/categories, as a result most of your best content receives no attention at all. A random post slider is the best way to showcase your oldest posts to your visitors. The slider widget will pick your old posts randomly and automatically display the thumbnails either on homepage or sidebar depending on what location best suits you. The slider rotates in a clockwise direction where each slide is both responsive and dynamic.

    Features of Blogger Random Post Slider Widget

    Each slide will display useful data which is fetched using a JSON Call. Features supported include:

    • Article comments count,
    • Author avatar,
    • Author name,
    • Published date,
    • Labels,
    • Featured Thumbnail,
    • Third Party Thumbnail Support,
    • YouTube Thumbnail Support,
    • Editable Title,
    • Mobile responsive (Smartphones/ Tablets/ Laptops/ Desktop Screens supported)

    Create and Random Post Slider in Blogger

    Follow these easy steps:

    1. Go To Blogger > Template
    2. Backup your template
    3. Click "Edit HTML"
    4. Just below <head> tag paste the following JS and CSS source links:

      <script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>
      <link href='http://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css' rel='stylesheet'/>
      <link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'/>
      <link href='https://cdnjs.cloudflare.com/ajax/libs/flexslider/2.6.1/flexslider.min.css' rel='stylesheet' type='text/css'/>
      <script src='https://cdnjs.cloudflare.com/ajax/libs/flexslider/2.6.1/jquery.flexslider.min.js' type='text/javascript'></script>

      Note: Do not add JQuery, FontAwesome, FlexSlider or Oswald source links to your template if you are already using them on your site.

    5. Next search ]]></b:skin> and just above/before it paste the following code:

      /*######### Random Posts By MyBloggerTricks #############*/
      .mbt-random{margin:0 5px;border:0;width:100%;overflow:hidden}
      .mbt-random .slides{list-style-type:none;margin:0 auto;padding:0}
      .mbt-random li{color:#fff;font-family:helvetica;font-size:12px;overflow:hidden;padding-top:10px}
      .mbt-random .flex-control-nav li{display:inline-block;margin:0 2px}
      .mbt-random .flex-control-nav a{text-indent:9999px;display:block;width:10px;cursor:pointer;height:10px;background-color:#000;border:1px solid #000;border-radius:0!important}
      .flex-direction-nav .flex-prev{left:-50px}
      .flex-direction-nav .flex-next{right:-50px;text-align:right}
      .mbt-random .flex-control-paging{display:none}
      .flex-direction-nav{position:relative;top:-250px}
      .mbt-random .flex-control-nav a.flex-active{background-color:#84db06;border:1px solid #90f128}
      .mbt-random .flex-div{margin:0 auto;display:block;padding:0!important;position:relative;height:370px}
      .mbt-random li a{color:#0080ff;text-decoration:none}
      .mbt-random i{color:#999;padding-right:5px}
      .mbt-random .iline{line-height:2em;margin:0;position:relative;top:-90px;background:#56adff;padding:3px 10px;display:inline-block}
      .mbt-random .icontent{line-height:1.5em;margin-top:5px}
      .mbt-random div span{margin:0 5px 0 0;display:inline-block;font-weight:400}
      .mbt-random .mbttitle{font-family:oswald;font-size:20px;color:#fff;font-weight:400;text-decoration:none;position:relative;top:-90px;background:#66b5ff;padding:15px 10px;display:block}
      .mbt-random .mbttitle:hover,.mbt-random .itotal a:hover{color:#fff;text-decoration:none}
      .mbt-random .iedit a{text-decoration:none;color:#999;cursor:pointer}
      .mbt-random .iedit:before,.mbt-random .iauthor:before,.mbt-random .itag:before,.mbt-random .icomments:before,.mbt-random .idate:before,.mbt-random .itotal span:before{font-family:fontAwesome;position:relative;padding-right:8px;color:#fff}
      .mbt-random .iauthorpic{width:17px!important;height:17px!important;border-radius:50%;float:none;display:inline-block!important;margin:0;padding-right:3px;position:relative;top:3px}
      .mbt-random .iFeatured{overflow:hidden;position:relative;margin:0;padding:0;width:100%}
      .mbt-random .iFeatured a{background:none;padding:0;display:block;border:0px solid #eee;margin:0 -1px}
      .mbt-random .iFeatured img{height:305px!important;-moz-transition:all .3s;-webkit-transition:all .3s;transition:all .3s;border-radius:0;margin:0;padding:0;opacity:.7}
      .mbt-random .iFeatured:hover img{opacity:1;-moz-transform:scale(1.4);-webkit-transform:scale(1.4);transform:scale(1.4)}
      .mbt-random .icomments a, .mbt-random .itag a{color:#0080ce;font-family:arial;font-size:12px}
      .mbt-random .icomments a:hover, .mbt-random .itag a:hover{text-decoration:underline}
      .mbt-random .itag:before{content:'\f02c';padding:0 3px 0 7px;color:#fff}
      .mbt-random .icomments:before{content:'\f086';padding:0 3px 0 7px;color:#fff}
      .mbt-random .idate{color:#fff;padding:3px 4px;font-family:arial;font-size:11px}
      .mbt-random .idate:before{content:'\f073';padding:0 5px;color:#fff}

    6. Make these changes

      • To change the blue background color behind the title edit: #66b5ff
      • To change the light blue background behind Author name edit: #56adff
      • To change the white color of the Title text edit: #fff
      • To change the color of the comment and labels link edit: #0080ce
    7. Save your template.
    8. Now go to Blogger > Layout
    9. Select "Add a Gadget"
    10. Choose "HTML/JavaScript" gadget
    11. Keep the title field empty and then paste the following code inside it:

      <script type="text/javascript">
      //################### Defaults
      var ListBlogLink = "http://mybloggertricks.com";
      var ListCount = 4; 
      var TitleCount = 66;
      var ImageSize = 800;

      $(window).load(function() {
        $('.mbt-random').flexslider({
         animation: "slide",
          itemWidth: 600,
      itemMargin: 25,
        directionNav: true,
             touch: true,
             slideshowSpeed: 2500,
            pauseOnHover: true,
           animationSpeed: 700,
        });
      });

      var RandomArray = [];
      var TotalPosts  = 0;
      var RandomArray = new Array(ListCount);
      function TotalCount(json) {
          TotalPosts   = json.feed.openSearch$totalResults.$t
      }
      document.write('<script type=\"text/javascript\" src=\"'+ListBlogLink+'/feeds/posts/default?alt=json-in-script&callback=TotalCount\"><\/script>');

      function GenerateNum() {
          for (var i = 0; i < ListCount ; i++) {
          for (var j = 0; j < RandomArray.length; j++){
          var RandomNum = Math.floor(Math.random() * (TotalPosts ) + 1);
          RandomArray[i] = RandomNum; }
                                                                        }
      }

      </script>

      <div class="flexslider mbt-random">
      <ul class="slides">
      <script type="text/javascript">
      //################### Function Start
      function mbtrand(json) {
      for (var i = 0; i < json.feed.entry.length; i++)
      { 
      //################### Variables Declared
      var listing= ListImage = ListUrl = ListTitle = ListImage = ListContent = ListConten = ListAuthor = ListTag = ListDate = ListUpdate = ListComments = thumbUrl = TotalPosts = sk = AuthorPic= ListMonth = Y = D = M = m = YY = DD = MM = mm = TT =  "";
      //################### Category

      if (json.feed.entry[i].category != null)
      {
      for (var k = 0; k < json.feed.entry[i].category.length; k++) {
      ListTag += "<a href='"+ListBlogLink+"/search/label/"+json.feed.entry[i].category[k].term+"'>"+json.feed.entry[i].category[k].term+"</a>";
      if(k < json.feed.entry[i].category.length-1)
      { ListTag += ", ";}
      }
      }
      //################### URL
      for (var j = 0; j < json.feed.entry[i].link.length; j++) {
            if (json.feed.entry[i].link[j].rel == 'alternate') {
              break;
            }
          }
      ListUrl= "'" + json.feed.entry[i].link[j].href + "'";
      //################### Info
      TotalPosts = json.feed.openSearch$totalResults.$t;
      if (json.feed.entry[i].title!= null)
      {
      ListTitle= json.feed.entry[i].title.$t.substr(0, TitleCount);
      }
      if (json.feed.entry[i].thr$total)
      {
      ListComments= "<a href='"+json.feed.entry[i].link[j].href+"#comment-form'>"+json.feed.entry[i].thr$total.$t+"</a>";
      }
      ListAuthor= json.feed.entry[i].author[0].name.$t.split(" ");
      ListAuthor=ListAuthor.slice(0, 1).join(" ");
      AuthorPic = json.feed.entry[i].author[0].gd$image.src;
      //################### Date Format
      ListMonth= ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
      ListDate= json.feed.entry[i].published.$t.substring(0,10);
                               Y = ListDate.substring(0, 4);
                              m = ListDate.substring(5, 7);
                               D = ListDate.substring(8, 10);
                               M = ListMonth[parseInt(m - 1)];                      
      ListUpdate= json.feed.entry[i].updated.$t.substring(0, 16);
                               YY = ListUpdate.substring(0, 4);
                              mm = ListUpdate.substring(5, 7);
                               DD = ListUpdate.substring(8, 10);
                               TT = ListUpdate.substring(11, 16);
                               MM = ListMonth[parseInt(mm - 1)];  
      //################### Thumbnail Check

      if (json.feed.entry[i].media$thumbnail)
      {
      thumbUrl = json.feed.entry[i].media$thumbnail.url;
      sk= thumbUrl.replace("/s72-c/","/s"+ImageSize+"/");
      ListImage= "'" + sk.replace("?imgmax=800","") + "'";
      }

      // YouTube scan
      else if (json.feed.entry[i].content.$t.match(/youtube\.com.*(\?v=|\/embed\/)(.{11})/) != null)
      {
          var youtube_id = json.feed.entry[i].content.$t.match(/youtube\.com.*(\?v=|\/embed\/)(.{11})/).pop();
         
          if (youtube_id.length == 11) {
              var ListImage = "'//img.youtube.com/vi/"+youtube_id+"/0.jpg'";
              }
      }

      else if (json.feed.entry[i].content.$t.match(/src=(.+?[\.jpg|\.gif|\.png]")/) != null)
      {
      // Support For 3rd Party Images
      ListImage =  json.feed.entry[i].content.$t.match(/src=(.+?[\.jpg|\.gif|\.png]")/)[1];
      }
      else
      {
      ListImage= "'https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGBaoO_i2u7kTRZvG6GBbHHO97n5RtxCjYQeBEoyXWIVKquEE5xXh4kgUGZnVBKy5yfkOYCTitIMnhUgO8zZHT7Oa0SN5EEVh5JgdI3KUj66cqgZ7EVuzPXOV_pewp5n0Ydrog0K1Rdfs/s200/Icon.png'";
      }
      //###################  Printing List
      var listing = "<li><div class='flex-div'><div class='iFeatured'><a  href="
      + ListUrl+
        "><img src="
      +ListImage+
      "/></a></div><div class='iline'><span class='iauthor'><img class='iauthorpic' src='"+AuthorPic+"'/>"
      +ListAuthor+
      "</span><span class='icomments'>"
      +ListComments +
      "</span> <span class='idate'>"
      + D +
      " "
      + M +
      "</span><span class='itag'>"
      +ListTag +
      "</span></div><a class='mbttitle' href="
      +ListUrl+
      "target='_blank'>"
      +ListTitle+
      "</a></div></li>";

      document.write(listing);

      } }
      <!-- #### Invoking the Callback Function #### -->
      for (var i = 0; i < ListCount ; i++) {
      GenerateNum();
      var scripta = '<script type=\"text/javascript\" src=\"'+ListBlogLink+'/feeds/posts/default?alt=json-in-script&start-index='+RandomArray[i] + '&max-results=1&callback=mbtrand\"><\/script>';
      document.write(scripta);
      };

      </script>
      </ul></div>

      Make these changes to customize the slider:

      • Place your blog URL inside ListBlogLink
      • Inside ListCount  mention how many slides to display. I recommend not displaying more than 3 or 4 slides. Increasing this number will increase the number of iterations/loops and thus slowing down your site.
      • Inside TitleCount  mention the length of title characters to display. By default titles longer than 66 characters will be trimmed.
      • Inside ImageSize mention the aspect ratio or resolution of your featured thumbnails. By default the thumbnails will be 800px in width. If you wish to display the slider in sidebar only then you can decrease this value to 400px.
    12. Click Save and you are all done!

    You have now successfully created blogger random post slider and have installed it on your blog template. Visit your blog to see it working just fine. If in case you troubleshoot yourself, feel free to leave your comments below and I would love to help you with all your queries.

    I have installed a random post widget on my blog slider and so far it has really helped growing our audience. I wish this slider may help you equally. This is the first random slider widget of its kind published online for blogger blogs therefore do let us know how useful is this slider for you and what is your experience after installing it successfully on your template. Peace buddies! :)

    If you are interested to learn how are blogger widgets developed and coded then do read:

    More

    Featured Image Slider Widget For Blogger - [Responsive]

    Blogger Image Slider - Static and ResponsiveWe have so far discussed different types of dynamic slideshows and carousels for blogspot blogs but since some of you requested a featured image slider where you could display static posts based on your selection, so I thought of sharing a jQuery featured Image Slider where you can add custom info to feature your favorite blog posts on your homepage. If in case you want to display images automatically based on a specific label please check: Dynamic Blogger Slider.
    More

    Featured Posts Slider Widget for Blogger - [Automatic]

    dynamic blogger sliderEver wondered how to display your most recent posts from a selected category inside a dynamic Image slider? Let's create a responsive featured content slider widget for BlogSpot blogs that may display recent posts from a specific label automatically. Without our Blogger JSON Feeds guide, building Blogspot widgets would not have been that easy!
    UPDATE: We just released Random Posts Slider Widget and a Static Slider For Blogger!
    Image Sliders for blogs play a vital role in showcasing your featured content whether it be a static list of featured images linked to your bog posts or a dynamic/automatic list of recent posts from a specific label or an automatic list of random posts. We are sharing with you all for the first time, all these three amazing blogger featured content sliders built using FlexSlider and Blogger JSON Feeds API. These blogspot widgets are rarely shared with all advanced functionality and we are pleased to develop them exclusively for blogger community. 
    In the past we have developed and shared several static Content Sliders for Blogspot blogs but this time we will learn how to make that content load dynamically instead of manually creating the featured content list and then displaying it.
    More

    Blogger Carousel: Responsive & Dynamic Slider

    Blogger Carousel (BC) helps you to create dynamic slideshows to showcase your blog posts by a specific category/label. You can use carousels in Blogspot to automatically display a list of latest posts inside an animated cycle. Blogger carousel is a mobile responsive widget that adapts perfectly to different screen sizes because it supports multiple breakpoints. It uses Blogger JSON Feeds to dynamically display recent posts from any label you specify. It is a responsive basic carousel plugin created using FlexSlider by Woothemes. You can display multiple thumbnails organized horizontally inside the carousel with navigational controls.
    Blogger Carousel For Blogspot Blogs
    We have already shared two jQuery carousel sliders for blogspot blogs that you can add to your blog by reading the following tutorials:
    More

    Most Dynamic Random Posts Widget For Blogger

    Random Posts Widget For BloggerBlogger random posts widget shows a random list of your blog posts with thumbnails, title, comments count, date, label tag and author avatar. It is really important to send traffic to your old posts and keep highlighting them. Random Posts gadget helps your readers to take a quick look at some of the older posts that they might have missed reading. It attracts readers attention towards oldest posts thus helping you with increased pageviews and higher revenue. This widget displays both label links and author avatar which are the two features first time introduced for blogspot blogs and thus makes this widget extremely unique. It is built using Blogger JSON Feeds technique that we have discussed in detail.

    More

    Automated Recent Posts Slider For Blogger - [FlexSlider]

    Blogger Recent Posts Slider WidgetToday we will create a dynamic and automated recent posts slider for blogger using Blogger JSON Feed and jQuery. We will display recent posts of your blog inside FlexSlider which is a free slider plugin provided by woothemes. The slider  gives a feeling of a tab widget where you can switch from one slide to another using the tab buttons or navigational controls. WordPress users have already integrated recent posts inside flexslider but this is the first time blogspot users will be able to display automatic list of recent posts inside a image slider.
    More

    Recent Posts Gadget With Avatar, Animated Thumbnails & Labels

    Recent Posts Gadget For  BloggerBlogger Recent Posts Gadget with label support is the backbone behind fancy templates being designed these days. We have covered a detailed full series on how these widgets are coded using Blogger JSON Feeds. Today I will share the most advanced Recent Posts gadget for blogspot blogs unlike shared before. It is not only rich in features but also well optimized, responsive and loads lightening fast. It is a two-in-one gadget that can be used to either display latest posts of your blog or latest posts from a specific label. The logic it uses can also be modified to display Random Posts and Related Posts. All these gadgets will be shared this month inshAllah. These gadgets can be completely customized using CSS and its features can be switched on/off using simple Boolean logic.

    If you wish to add animation to this widget please read:

    More

    Display Recent Posts With Featured Thumbnails in Blogger

    recent posts widget with thumbnailsWe have discussed in detail how you can use JavaScript to extract data from Blogger JSON Feed API and use it to build gadgets such as "Recent Posts Widget" and "Recent Comments Widget". The JSON tutorial series would help a developer to create quality widgets for blogspot blogging platform. Today's tutorial will show you the end-product of what can be done using JSON feed for posts. I will share with you an advanced widget that will display recent posts in descending order (latest at top) along with post thumbnails, post summary, timestamp, comment count, label tag, author name and edit link. You can add it to your blogger blogs to display latest posts in a unique style. This is the first widget of its kind with so much features. See the demo below:

    Update: A more compact, flexible and fully functional version of this widget has been released. Checkout:

    DEMO - Look at footer

    What is a Blogger Recent Posts Widget?

    A recent posts widget displays your latest posts in descending order with newest at top. It shows a list of your latest blog posts along with thumbnails, post excerpt and post meta info. It works with all blogspot blogs. Copy the code and paste it inside a HTML/JavaScript gadget, that simple!

    You can also use it to display posts by label by listing recent posts from a specific label. You can customize it to display posts in magazine style fashion with vertical, horizontal, gallery style listing. I will discuss all such possibilities in my coming tutorials. Developers at themeforest use the same method to create magazine style blogger templates. You will learn how to code it from scratch through our JSON series.

    Full features are the following:

    1. Post Title
    2. Featured Image - With third party image support  and YouTube Thumbnails support
    3. Post summary
    4. Read more link
    5. Author Name
    6. Label/Category/Tag name
    7. Comments Count
    8. Publish date
    9. Edit link tooltip that will show post Update Date and Time.
    10. Lightweight
    11. Fluid and responsive

    Displays the following GIF preloader which spins and pulsates when the widget loads or when data is requested by browser from JSON feed.

    preloader for blogger blogs

    Once fully loaded the blog posts are displayed in descending order (Latest at top).

    recent posts widget with thumbnails

    See the difference in published date and updated date through the tooltip. A unique feature rarely seen before:

    recent posts widget with tooltip

    Lets get to coding!

    Add Recent Posts Widget To Your Blog

    Follow these easy steps to add this gadget to your blogspot blogs:

    1 Go To Blogger > Template

    2 Backup your template

    3 Click Edit HTML

    4 Paste the following code just above </head> tag

    Note: This step is optional. Skip it if you have already added jQuery library source links to your blogger template.

    <script async='' src='https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>

    5 Next paste the following stylesheet links for FontAwesome and Oswald font just above </head>. Skip adding the links if you already have added them inside your templates:

    <link href='http://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css' rel='stylesheet'/>

    <link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'/>

    6 Now paste the following CSS code just above    ]]></b:skin>

    /*############Recent Posts Widget##################*/

    .mbtlist {list-style-type:none;overflow:hidden; padding:10px!important;}
    .mbtlist li {margin:0px auto 20px auto; clear:both; color:#666; font-family:helvetica; font-size:12px; }
    .mbtlist i{color:#999; padding-right:4px; }
    .mbtlist .iline{line-height:2em; clear:both; border:1px solid #eee; margin-top:10px; padding: 0px 4px;   font-size: 12px;}
    .mbtlist div span{margin:0 10px 0 0; display:inline-block;}
    .mbtlist span {display:block; margin:5px 0px 0px; padding-right:5px;}
    .mbtlist .icon {color: #999;font-family: verdana;font-size: 12px;text-align: justify;}
    .mbtlist img {float:left; margin:0px 10px 10px 0px; border:6px solid #fff; padding:0px; width:150px; height:100px; box-shadow:-1px -1px 4px #777; }
    .mbtlist .mbttitle {font-family:oswald; font-size:18px; color:#0080ff; font-weight:normal; text-decoration:none;    line-height: 1.4em;}
    .mbtlist .mbttitle:hover, .mbtlist .itotal a:hover  {color:#00A5FF;}
    .mbtlist .iedit a{text-decoration:none; color:#999; cursor:pointer}
    .mbtlist .iedit:before, .mbtlist .iauthor:before, .mbtlist .itag:before, .mbtlist .icomments:before, .mbtlist .idate:before, .mbtlist .itotal span:before{font-family:fontAwesome; position:relative; padding-right:5px;}
    .mbtlist .iauthor:before {content:'\f007';}
    .mbtlist .itag:before {content:'\f02c';}
    .mbtlist .icomments:before {content:'\f086';}
    .mbtlist .idate:before {content:'\f017';}
    .mbtlist .iedit:before {content:'\f040';}.mbtlist .imore {font-size:12px; font-weight:bold; text-decoration:none; color:#999;}.mbtlist .itotal {color:#333;  padding:5px 10px; border:1px solid #eee;}.mbtlist .itotal a {font-family:oswald; font-size:12px; font-weight:normal; color:#0080ff; text-decoration:none}.mbtlist .itotal span:before {content:'\f07c';}.mbtlist .itotal span font {padding:0px 3px; color:#333; font-family:georgia; font-size:15px; font-weight:bold}#mbtloading1{ margin: 20% auto;
    background: url('http://downloads.mybloggertricks.com/Spin%20and%20pulsate.gif') no-repeat left center;width: 80px;height: 80px;}

    /*------ CSS3 Tooltip Shortcode -------------*/
    .tooltip1{outline:none;text-decoration:none!important;position:relative;color: orange!important; font-weight: bold;}.tooltip1:hover {border-bottom: none;}.tooltip1 strong{line-height:30px}.tooltip1 > span{max-width:300px;width:115px;padding:5px 8px;opacity:0;bottom:170%;left:0px; visibility:hidden;z-index:10;position:absolute;font-family:helvetica;font-size:12px;font-weight:bold;border-radius:2px;box-shadow:2px 2px 5px #999;-webkit-transition-property:opacity,margin-top,visibility,margin-left;-webkit-transition-duration:0.4s,0.3s,0.4s,.3s;-webkit-transition-timing-function:ease-in-out,ease-in-out,ease-in-out,ease-in-out;transition-property:opacity,margin-top,visibility,margin-left;transition-duration:0.4s,0.3s,0.4s,.3s;transition-timing-function:ease-in-out,ease-in-out,ease-in-out,ease-in-out}.tooltip1 > span img{float:right;width:110px;margin:0 0 30px 10px;padding: 0;border: none;}.tooltip1:hover > span{opacity:1;text-decoration:none;visibility:visible;overflow:visible;display:inline;margin-left:-90px}.tooltip1 span b{width:15px;height:15px;right:25px;bottom:-9px;display:block;position:absolute;-webkit-transform:rotate(-45deg);-moz-transform:rotate(-45deg);-o-transform:rotate(-45deg);transform:rotate(-45deg);display:none\0/;*display:none}.tooltip1 > span{color:#fff;background:orange;border:1px solid #ffffff}.tooltip1 span b{background:orange;border-bottom:1px solid #ffffff;border-left:1px solid #ffffff}

    Edit the colors:

    • To change the blue color of the post title replace #0080ff with the link color of your choice and replace #00A5FF to change the link color for mouse hover.
    • To change the edit link color change orange
    • To change the tooltip color change orange with a hexadecimal color code of your preference.
    • To change the width and height dimensions of the featured thumbnail edit: width:150px; height:100px;

    7 Save your template and you are almost done!

    8 Finally go to Layout section and click "Add a Gadget".

    9 Choose HTML/JavaScript widget and paste the following code inside it:

    <div id="mbtloading1" ></div>
    <script type="text/javascript">

    //#################### Defaults
    var ListBlogLink = window.location.hostname;
    var ListCount = 5;
    var ChrCount = 150;
    var TitleCount = 66;
    var ImageSize = 200;
    //################ Function Start
    function mbtlist(json) {
    document.write('<ul class="mbtlist">');
    for (var i = 0; i < ListCount; i++)
    {
    //################### Variables Declared
    var listing= ListImage = ListUrl = ListTitle = ListImage = ListContent = ListConten = ListAuthor = ListTag = ListDate = ListUpdate = ListComments = thumbUrl = TotalPosts = sk = ListMonth = Y = D = M = m = YY = DD = MM = mm = TT =  "";

    //################### Category
    if (json.feed.entry[i].category != null)
    {
    for (var k = 0; k < json.feed.entry[i].category.length; k++) {
        ListTag += json.feed.entry[i].category[k].term;
    if(k < json.feed.entry[i].category.length-1)
    { ListTag += ", ";}
    }
    }

    //################### URL
    for (var j = 0; j < json.feed.entry[i].link.length; j++) {
          if (json.feed.entry[i].link[j].rel == 'alternate') {
            break;
          }
        }
    ListUrl= "'" + json.feed.entry[i].link[j].href + "'";

    //################### Info
    TotalPosts = json.feed.openSearch$totalResults.$t;
    if (json.feed.entry[i].title!= null)
    {
    ListTitle= json.feed.entry[i].title.$t.substr(0, TitleCount);
    }
    if (json.feed.entry[i].thr$total)
    {
    ListComments= json.feed.entry[i].thr$total.$t;
    }
    ListAuthor= json.feed.entry[i].author[0].name.$t.split(" ");
    ListAuthor=ListAuthor.slice(0, 1).join(" ");


    //################### Content Check

    ListConten = json.feed.entry[i].content.$t;
    ListContent= ListConten.replace(/(<([^>]+)>)/ig,"").substring(0, ChrCount);

    //################### Date Format

    ListMonth= ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

    ListDate= json.feed.entry[i].published.$t.substring(0,10);

                             Y = ListDate.substring(0, 4);
                            m = ListDate.substring(5, 7);
                             D = ListDate.substring(8, 10);
                             M = ListMonth[parseInt(m - 1)];                       

    ListUpdate= json.feed.entry[i].updated.$t.substring(0, 16);

                             YY = ListUpdate.substring(0, 4);
                            mm = ListUpdate.substring(5, 7);
                             DD = ListUpdate.substring(8, 10);
                             TT = ListUpdate.substring(11, 16);
                             MM = ListMonth[parseInt(mm - 1)];   

    //################### Thumbnail Check
    // YouTube scan

    if (json.feed.entry[i].content.$t.match(/youtube\.com.*(\?v=|\/embed\/)(.{11})/) != null)
    {

        var youtube_id = json.feed.entry[i].content.$t.match(/youtube\.com.*(\?v=|\/embed\/)(.{11})/).pop();
       
        if (youtube_id.length == 11) {
            var ListImage = "'//img.youtube.com/vi/"+youtube_id+"/0.jpg'";
            }
    }

    else if (json.feed.entry[i].media$thumbnail)
    {
    thumbUrl = json.feed.entry[i].media$thumbnail.url;
    sk= thumbUrl.replace("/s72-c/","/s"+ImageSize+"/");
    ListImage= "'" + sk.replace("?imgmax=800","") + "'";
    }

    else if (json.feed.entry[i].content.$t.match(/src=(.+?[\.jpg|\.gif|\.png]")/) != null)
    {
    // Support For 3rd Party Images
    ListImage =  json.feed.entry[i].content.$t.match(/src=(.+?[\.jpg|\.gif|\.png]")/)[1];
    }
    else
    {
    ListImage= "'https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGBaoO_i2u7kTRZvG6GBbHHO97n5RtxCjYQeBEoyXWIVKquEE5xXh4kgUGZnVBKy5yfkOYCTitIMnhUgO8zZHT7Oa0SN5EEVh5JgdI3KUj66cqgZ7EVuzPXOV_pewp5n0Ydrog0K1Rdfs/s200/Icon.png'";
    }
    //################### Printing List

    var listing = "<li class='node"+[i]+"' ><a href="
    + ListUrl+
      "><img src="
    +ListImage+
    "/></a><a class='mbttitle' href="
    + ListUrl+
    "target='_blank'>"
    + ListTitle+
    "</a> <span class='icon'>"
    +ListContent+
    " ...  <a href="
    +ListUrl+
    " class='imore'>more »</a></span><div class='iline'><span class='iauthor'>"
    +ListAuthor+
    "</span><span class='itag'>"
    +ListTag+
    "</span><span class='icomments'>"
    + ListComments+
    "</span><span class='idate'>"
    + M +
    " "
    + D +
    ", "
    + Y +

    "</span><span class='iedit'> <a class='tooltip1'>Edited<span><b></b>On ► "
    + MM +
    " "
    + DD +
    ", "
    + YY +
    " at ► "
    +TT+
    " </span></a> </span></div></li>";
    document.write(listing);
    }
    document.write("<div class='itotal'><span> <a href='"+ListBlogLink+"/search'>View all <font>"+TotalPosts+"</font> posts</a></span></div></ul>");
    }
    </script>

    <script>
    var ListBlogLink = "http://www.mybloggertricks.com";
    var ListCount = 5;
    </script>

    <script>
    document.write("<script src='"+ListBlogLink+"/feeds/posts/default?alt=json-in-script&callback=mbtlist'></"+"script>");
    </script>

    <script>
    document.getElementById("mbtloading1").style.display = "none";</script>

    You can make these changes:

    • Replace http://www.mybloggertricks.com this with your blog URL
    • To increase or decrease the number of posts entries, edit: ListCount = 5
    • To reduce the length of title characters edit TitleCount = 66
    • To increase the image resolution quality (aspect ratio) if incase you wish to display large featured thumbnails then edit ImageSize = 200
    • To decide how many characters to display as post summary (excerpt) edit:ChrCount = 150

    10 Save your widget and see it play in action! =)

    Can You Guess How To Display Posts By Label?

    At mbt we aim at educating the readers to learn the core basics of programming instead of just sharing a normal howto tutorial. In the above code you just need to make a simple change in order to display latest posts by a specific label. I have already discussed how to do that in the JSON series. Do read that and get back here proposing your solution mentioning all the necessary steps.

    I will be waiting for your answers, I will share it in my next tutorial and link to your blog if you answered correctly. =)

    More