A comment on a recent post asked ‘Please write a post showing how to have a subscribe section below posts but not on the read more page’.By read more page the commenter meant the home page and unfortunately although it was a genuine comment they included a link to their email in the comment so i couldn’t publish it (Are you seeking out spam bots :D).OK so basically this person had added the code for a subscribe section to the template and it displayed below all the posts on the home page even though the posts were just a short summery.What they wanted was for it only to be below the full posts and doing this is quiet simple.
Back in February 2010 i showed you how you can make gadgets only appear on the home page or post pages.This was for gadgets you added to your sidebar or other gadget sections.The very same technique is used here and it will work with anything you add to your template, we just do it in a different way.So if you only want the subscribe section, related posts or AdSense on the post pages this will do the trick.
Gadgets On Full Post Pages Only
When you add the html for a gadget to your blog we add a snippet of code above it and a closing tag below it.Remember for some gadgets you add Css, Script and Html this tag is only used on the html.A good rule of thumb for this is as follows.
Css will be the code you added above: ]]></b:skin>
Script will be the code you added above: </head>
So by elimination we know the code you add elsewhere in general will be the html, make sense ?
The Code Needed To Display On Only Post Pages
The tag we add to the html so it only appears on post pages is this :
<b:if cond='data:blog.pageType == "item"'>
THE-HTML-CODE-GOES-HERE-BETWEEN-THE-TAGS
</b:if>
So for the commenter who wanted his subscribe section on the full post pages only he would add the html for the subscribe section between the above code when adding it to his template.
Gadgets On Home Page Only
What about doing the opposite and having something on the home page only ?
No problem this time we add this tag to the html :
<b:if cond='data:blog.url == data:blog.homepageUrl'>
THE-HTML-CODE-GOES-HERE-BETWEEN-THE-TAGS
</b:if>
This is about as easy as i can make this, it’s always awkward when you are required to add code to code and add that to your template, see i made it sound even harder !
Advanced
How about some more ? You can use similar tags to define a number of other unique places gadgets will appear.
On Everything except post pages (home page, labels pages, archive pages)
<b:if cond='data:blog.pageType == "index"'>
THE-HTML-CODE-GOES-HERE-BETWEEN-THE-TAGS
</b:if>
On only one post or page :
<b:if cond='data:blog.url == "URL-OF-POST-OR-PAGE-HERE"'>
THE-HTML-CODE-GOES-HERE-BETWEEN-THE-TAGS
</b:if>
On only the static pages :
<b:if cond='data:blog.pageType == "static_page"'>
THE-HTML-CODE-GOES-HERE-BETWEEN-THE-TAGS
</b:if>
There is more but i think they would cover any needs you have.
In many posts i automatically add the post page only tags and then highlight them giving you the option to use them or not.In future i will make sure to add them to every tutorial and give you a heads up on what they do and how to remove them.
Drop your Comments and Questions Below.