Showing posts with label Ctags. Show all posts
Showing posts with label Ctags. Show all posts
About Blogger Conditional Tags and How To Use Them Properly

About Blogger Conditional Tags and How To Use Them Properly

Conditional tags provide us better control over our templates, allowing us to specify what part of our template appears only under certain conditions.

You may wish to hide a widget or element on one page and display it on the other, need to remove the sidebar on certain pages, or even display buttons on select pages. This is exactly where conditional tags come into play. There are a number of tags available for blogger which, if applied correctly, will help you modify elements of your template.

List of conditional tags

The following are a select few conditional tags you'll require the most:
  1. Homepage:
  2. <b:if cond='data:blog.url == data:blog.homepageUrl'>
  3. First post:
  4. For targeting the first post on multi-post pages.
    <b:if cond='data:post.isFirstPost'>
  5. Specific page/URL:
  6. <b:if cond='data:blog.url == "ENTER_URL_HERE"'>
  7. Posts (item):
  8. <b:if cond='data:blog.pageType == "item"'>
  9. Static pages:
  10. <b:if cond='data:blog.pageType == "static_page"'>
  11. Index pages (includes homepage, label pages and archive pages):
  12. <b:if cond='data:blog.pageType == "index"'>
  13. Archive pages:
  14. <b:if cond='data:blog.pageType == "archive"'>
  15. Posts and static pages:
  16. <b:if cond='data:blog.url == data:post.url'>
  17. Label-search pages:
  18. <b:if cond='data:blog.searchLabel'>
  19. 404 Error Page:
  20. <b:if cond='data:blog.pageType == "ERROR_PAGE"'>
  21. Mobile Pages:
  22. <b:if cond='data:blog.pageType == "data:blog.isMobile"'>

How to Use conditional tags


Using conditional tags is simple. Each tag needs to be closed with a closing </b:if> tag. All you have to do is select the suitable tag and place the content between the opening and the closing tag like this:
<b:if cond='THE_CONDITION_GOES_HERE'>
...
</b:if>
For Example:
You need to display the content only on Index Pages (homepage, archives and labels page). The following tag will be applied:
<b:if cond='data:blog.pageType == "index"'>
...ENTER CONTENT HERE...
</b:if>
The double equals " == " actually means TRUE. You can change the condition to FALSE, then just replace the first equal with an exclamation sign: " != ".

Reversing a Condition:

Example:
<b:if cond='data:blog.pageType != "index"'>
... THE CONTENT ...
</b:if>
In the example above, the content will show up on all pages other than "index" pages.

The ELSE Statement <b:else/>:

In case you need to display alternate content, insert a <b:else/> tag like this:
<b:if cond='data:blog.pageType == "index"'>
...Content 1...
<b:else/>
...Content 2...
</b:if>
In the example above "Content 1" will only appear on Index Pages (homepage, archives and labels page), and if its not an Index Page, "Content 2" will be displayed.

Combining Conditions Together:

<b:if cond='data:blog.pageType == "item"'>
<b:if cond='data:blog.url != "URL_OF_POST_TO_EXEMPT"'>
...ENTER CONTENT HERE...
</b:if>
</b:if>
Finally, in the example above, the content will show up on all posts except a certain URL/Post specified.

How to Add Adsense Ads After First Post On Blogger Homepage

How to Add Adsense Ads After First Post On Blogger Homepage

Displaying Adsense or other ads on blogger is as simple as adding it to WordPress or other blogging platforms. You just copy and paste the code on to the template. But adding it precisely where and how you wan't it can sometimes be tricky and may not display as desired. This is exactly where blogger conditional tags come in handy. They provide us better control over our widgets and other elements.

Among the several conditional tags available for blogger, one is specifically written to target the first post - a good position for displaying ads. And here's how you too can insert Adsense after the first post on your blogger blog:

The Steps:
  1. Login to Blogger Dashboard
  2. Go to Template > Edit HTML
  3. Find this line of code in your template
  4. <b:include data="post" name="post">
    
  5. Add the following code just below the code above
  6. <b:if cond='data:blog.pageType == &quot;index&quot;'>
    <b:if cond='data:post.isFirstPost'>
    
    ---- Replace this line with your Adsense Code -----
    </b:if> </b:if>
  7. Finally grab a suitable Adsense unit, parse it and add it to the code above

That's it. You can now monitor the newly added ad unit for clicks.