Show Widgets Only in Homepage or in Post Pages

Once you activate any widget, in your blog, it will be displayed in all the pages by default, including your homepage.
But sometimes, we do want to show some widgets only on Homepage or only for the individual posts pages, or only in a specific page, the coding is quite simple, but you need to customize the widget through the "Edit HTML" link in your "Layout" section.
Follow these steps:
Create any widget, and place it where-ever you want, and save the template. Check if it is working (should be displayed in all the pages). Remember to give a TITLE to it, like Archives/BlogRoll/Maps/Clock, anything unique.

Now go to "Edit HTML" page.
Click/mark "Expand Widget Templates"
Then find for that unique Title (by searching through CTRL+F method)
It will be something like this:











<b:widget id='HTML3' locked='false' title='UNIQUE WORD OR TITLE HERE' type='HTML'>
<b:includable id='main'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != &quot;&quot;'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>
<b:include name='quickedit'/>
</b:includable>
</b:widget>
Now tweak this as follows
CASE #1
To SHOW the code/widget only in HomePage











<b:widget id='HTML3' locked='false' title='UNIQUE WORD OR TITLE HERE' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.url == data:blog.homepageUrl'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != &quot;&quot;'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>
<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>
CASE #2
To SHOW the widget in "All Posts", but NOT in HomePage











<b:widget id='HTML3' locked='false' title='UNIQUE WORD OR TITLE HERE' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.pageType == "item"'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != &quot;&quot;'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>
<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>
CASE #3
To SHOW the widget in any particular page










<b:widget id='HTML3' locked='false' title='UNIQUE WORD OR TITLE HERE' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.url == "SPECIFIC_BLOG_POST_URL"'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != &quot;&quot;'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>
<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>









Add those code lines in red color, as per your requirement.


CASE #4
To HIDE a widget ONLY in a particular page/post, and to display it in all other pages of your blog, use this code (shown below is only the code in RED from the previous code):









...
...
<b:if cond='data:blog.url != "SPECIFIC_BLOG_POST_URL"'>
...
...
...
</b:if>
...
...
CASE #5
To SHOW widgets only in Archive Pages






...
...
<b:if cond='data:blog.pageType != "static_page"'>
...
...
...
</b:if>
...
...
CASE #6
To SHOW widgets only in Static Pages



...
...
<b:if cond='data:blog.pageType != "static_page"'>
...
...
...
</b:if>
...
...


CASE #7




To HIDE widgets in Static Pages


...
...
<b:if cond='data:blog.pageType != "static_page"'>
...
...
...
</b:if>
...
...

No comments:

Post a Comment