Show Limited Number of Labels in Widget.

As you write more and more posts you will keep adding labels to them to categorize your posts. You can add more than one label to any single post. Labels are useful as they serve as keywords channelling traffic to your posts through search engines like Technorati.

However the list of labels in your blog can get to be very long stretching your sidebar until y

our blog post looks like a flag on top of a long sidebar. To prevent this you can modify the code of your Labels widget to show only the topmost labels in your blog..............


LIMIT LABEL NUMBER
To limit the number of labels shown in your Labels sidebar widget login at Blogger.com and click 'Layout' link on Dashboard. The Page Elements subtab of Template tab will open. If you do not have a Labels widget in the sidebar Add a Labels Page Element to it.

After the Labels widget is added click on Edit Html subtab of Template tab. This will open the Template code box on the Edit Html subtab. Click the Expand Widgets Template checkbox on top of the Template code box to put a check mark in it. The Template code box will show the expanded widgets templates.

Scroll down in the Template code box to locate the code for the Labels widget. This will look like this :

<b:widget id='Label1' locked='false' title='Labels' type='Label'>

  <b:includable id='main'>
<b:if cond='data:title'>

  <h2><data:title/></h2>

  </b:if>

  <div class='widget-content'>

  <ul>

  <b:loop values='data:labels' var='label'>

  <li>

  <b:if cond='data:blog.url == data:label.url'>

  <span expr:dir='data:blog.languageDirection'>

  <data:label.name/>

  </span>

  <b:else/>

  <a expr:dir='data:blog.languageDirection' expr:href='data:label.url'>

  <data:label.name/>

  </a>

  </b:if>

  <span dir='ltr'>(<data:label.count/>)</span>

  </li>

  </b:loop>

  </ul>
<b:include name='quickedit'/>

  </div>

  </b:includable>

  </b:widget>

REPLACE THE WHOLE ABOVE CODE WITH THE CODE BELOW :

<b:widget id='Label1' locked='false' title='Labels' type='Label'>

<b:includable id='main'> 

<b:if cond='data:title'>

<h2><data:title/></h2>

</b:if>

<ul>

<script type='text/javascript'>

var labelnum = 0;

<b:loop values='data:labels' var='label'>

if (<data:label.count/> &gt; 2) {

document.write(&quot;<li><a expr:href='data:label.url +  "?max-results=100"' 

rel='nofollow'><span><data:label.name/></span></a>(<data:label.count/>)</li>&quot;);

}

</b:loop>

</script>

</ul>

<b:include name='quickedit'/>

</b:includable>

</b:widget>

The code above will only show labels with more than two posts. To increase number of labels increase the number two in this code :
if (<data:label.count/> &gt; 2) {

0 comments: