Kamis, 28 Juli 2011

Membuat widget yang hanya tampil pada halaman atau posting tertentu saja

So first go to Blogger’s Dashboard > Design > Page Elements tab and add a “HTML/JavaScript” gadget. I prefer it because it will be easy for everyone to understand. Give it a unique tile so that it does not match with any of the titles of other widgets added (if any).
Now got to Design > Edit HTML tab and check “Expand Widget Templates”. Now press “Ctrl+F” on your keyboard to open the browser’s search bar and search for the “unique” title that you have given to your gadget. Let’s say I have given the title for my widget as “My Widget”. After searching you will find the below snippets:
<b:widget id='HTML1' locked='false' title='My Widget' type='HTML'>
<b:includable id='main'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:includable>
It's the widget/gadget that you have added from Page Elements tab. All is left is to add conditional tags just below <b:includable id='main'> and above </b:includable> to hide the widget form specific pages or posts in Blogger. Let us see some examples:

Show Blogger Widget in Post Pages only

If you want to hide any widget or gadget from showing it on homepage or other page and to show it on post pages then you have to add the conditional tags as shown below:
<b:includable id='main'>
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:if>
</b:includable>

Show Blogger Widget in Homepage and Other Pages (except post pages)

<b:includable id='main'>
<b:if cond='data:blog.pageType == &quot;index&quot;'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:if>
</b:includable>

Show Widget on Particular Post

<b:includable id='main'>
<b:if cond='data:blog.url == &quot;URL of the page&quot;'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:if>
</b:includable>
Pakai bahasa inggris nih. Emang dia kopi paste daro sono. Artinya? masing-masing saja.

0 komentar:

Posting Komentar

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More