Thursday 26 March 2015

How To Show/Hide Widgets On Specific Pages In Blogger

There are some situations where you want show or hide certain widgets on particular pages such as home page,post pages,static pages,archive pages and even on particular posts.So many people have question such as "How to show/hide widgets on paricular pages".Because there are some widgets which are meant for home page and some for static pages or post pages.Let us take an example of adsense widget.A normal adsense publisher is allowed to show maximum of 3 ads(display ads) on each page,if you show more than that it may lead to ban.Also we are not allowed show adsense ads inside contact us,privacy policy page.So i'm here to explain you how to do it,so lets start jump into the topic.Follow the steps below.

Step 1:
Go to Blogger Dashboard>Layout and find a widget which you want to show or hide.After finding just give it a unique name which doesn't match any other widget name and click on save.Generally we add custom widgets using Html/Css widget and use with particular name to it.
Step 2:
Now click on Template>Edit html and check the expand widget in the template or html editor.
Step 3:
Next click ctrl+f and enter the name which you have given in step 1.Let us consider the widget name as Popular posts and click Enter until you find the code which is simailar to below code.

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
      
    Widget code

  </b:includable>
</b:widget>


Here Green highlighted name is the Title of widget which we are finding and the Red highlighted code is the widget code(bunch of code for widget) which is different for different widgets.In the above code id,title and type are also different for different widgets.Don't bother about widget code because we are not going to change it. :)
Step 4:
Now we need to show or hide widget on particular pages.We have to just use a conditional statement to do this job as shown below.

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
    <b:if cond='data:blog.pageType != "Page_type"'>

      Widget code

    </b:if>
  </b:includable>
</b:widget>

The above code is just a sample code with a conditional statement which is highlighted by Orange color.

Step 4:
Now i will give you the exact way(code) to show or hide widgets on different pages.

To Show Blogger Widget only in Homepage

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
    <b:if cond='data:blog.pageType == data:blog.homepageUrl'>

      Widget code

    </b:if>
  </b:includable>
</b:widget>

To Hide Blogger Widget only in Homepage

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
    <b:if cond='data:blog.pageType != data:blog.homepageUrl'>

      Widget code

    </b:if>
  </b:includable>
</b:widget>

To Show a Widget only in Post Pages

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
    <b:if cond='data:blog.pageType == "item"'>

      Widget code

    </b:if>
  </b:includable>
</b:widget>

To Hide a Widget only in Post Pages

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
    <b:if cond='data:blog.pageType != "item"'>

      Widget code

    </b:if>
  </b:includable>
</b:widget>

To Show a Widget only in a Specific Page or post

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
    <b:if cond='data:blog.pageType == "URL of the page or post"'>

      Widget code

    </b:if>
  </b:includable>
</b:widget>


Replace URL of the page or post(which is highlighted with Blue colour) with URL of the page or post where you want to show the widget.

To hide a Widget only in a specific Page or post

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
    <b:if cond='data:blog.pageType != "URL of the page or post"'>

      Widget code

    </b:if>
  </b:includable>
</b:widget>


Replace URL of the page or post(which is highlighted with Blue colour) with URL of the page or post where you want to show the widget.

To Show a Widget only in Static Pages

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
    <b:if cond='data:blog.pageType == "static_page"'>

      Widget code

    </b:if>
  </b:includable>
</b:widget>

To Hide a Widget only in Static Pages

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
    <b:if cond='data:blog.pageType != "static_page"'>

      Widget code

    </b:if>
  </b:includable>
</b:widget>

To Show a Widget only in Archive Pages

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
    <b:if cond='data:blog.pageType == "archive"'>

      Widget code

    </b:if>
  </b:includable>
</b:widget>

To hide a Widget only in Archive Pages

<b:widget id= 'HTML11' locked='false' title='Popular posts' type='HTML'>
  <b:includable id='main'>
    <b:if cond='data:blog.pageType != "archive"'>

      Widget code

    </b:if>
  </b:includable>
</b:widget>


After adding the code of conditional tags save your template. :)
You can also nest the conditional tags to show or hide widget on specific pages
If you have any queries or getting some problems feel free to comment.

Source: http://www.tricksladder.com/2014/06/showhide-widgets-on-specific-pages-in.html 

More: http://helplogger.blogspot.com/2012/03/hideshow-widgetsgadgets-in.html


No comments:

Post a Comment