How to Hide Blogger Widgets on Home Page


Recently I revised BPwebnews to show post excerpts on the homepage. The revision made the theme a magazine style, with 'read more' links. So now, there is no need to list recent articles in the sidebar on the home page. The 'recent posts' gadget is still useful when visitors arrive on a specific post --- they need only look in the sidebar for other articles that might interest them. This post will show you how to hide gadgets depending on which type of page is viewed.


Revise the template to hide recent posts on the home page.
  1. Go to Blogger Dashboard, Select Layout, Edit Html.
    Create a backup of your template by pressing "download full template."



    Check the Expand Widget box so you can find the right code.



  2. Basically, you'll  find the section that contains the widget code, add a conditional if-statement at the start of the 'includable' and an end-if tag just before the close of the last 'includable for that widget.' Search for the lines in green and insert the four red lines. (copy and paste). You must put them in the proper position.

    Here's all of the gadget code but you only need to add 2 lines after and 2 before the green sets. Remember your code might say gadget2 instead of gadget1, etc. Two of the red lines are optional comments, as they serve to identify the code if you need to remove it later. (<!-- >) 
    _____________




    <b:widget id='Gadget1' locked='false' title='Recent Posts' type='Gadget'>
    <b:includable id='main'>

    <!-- only display if not home page  -->
    <b:if cond='data:blog.pageType == "item"'> 

      <!-- only display title if it's non-empty -->
      <b:if cond='data:renderingUrl != &quot;&quot;'>
        <b:if cond='data:title != &quot;&quot;'>
          <h2 class='title'><data:title/></h2></b:if>
        <b:if cond='data:gadgetSnippet != &quot;&quot;'><data:gadgetSnippet/>
        <b:else/>
          <div class='widget-content'>
            <b:if cond='data:trackingUrl != &quot;&quot;'>
              <img expr:src='data:trackingUrl' height='1' width='1'/>
            </b:if><iframe expr:height='data:height' expr:id='data:moduleId' expr:name='data:moduleId' expr:src='data:renderingUrl' frameborder='0' style='width: 100%; display: block'>
            </iframe></div></b:if><b:else/><data:errorMessage/></b:if><b:include name='quickedit'/>
    <!-- added 9/2009 for non-homepage -->
    </b:if>
    </b:includable>




  3. Press the blue Preview button to see that the gadget is hidden on the home page.

    If there are errors, just 'clear edits' and backtrack, otherwise 'save template.'

Summary

You can use this method for any gadget by expanding your template and searching for the title you used in the sidebar. If you want to show something only on the homepage and not on single posts then instead of
<b:if cond='data:blog.pageType == "item"'>    use
 <b:if cond='data:blog.url == data:blog.homepageUrl'>


BPWebNews Bloggerspider logo
If you found this post useful, leave a comment to let me know. Grab the BPWebnews tips button and share the luv with others. Get future posts in your RSS feed or by email.



Print this post