Selective Display of Blogger Widgets on homepage, archive,post page, or particular pages

Before getting into the details of selective display,let us discuss about the different types of pages on blogger.
1) home page- yea its your blogs home page as the name suggests(actually this is not a type. but i will still include it here..)
2) Archive Page- Refers to archive pages..
3) Item Page - Refers to Post Pages
4) Index Page - Includes home page + label page + search results page

5) Static Page – The newly introduced Blogger Pages

Selective Display..

There are different conditions to check the page type. You can use these conditions for the selective display.

You might like to display a welcome message on the home page only..


<b:if cond='data:blog.canonicalUrl == data:blog.canonicalHomepageUrl'>
Welcome to my Blog
</b:if>


Displaying on all pages other than the homepage

<b:if cond='data:blog.canonicalUrl != data:blog.canonicalHomepageUrl'>
this is not the homepage
</b:if>


Displaying something on the Archive Pages..

<b:if cond='data:blog.pageType == &quot;archive&quot;'>
Hii this is an archive page
</b:if>


Displaying something on non Archive Pages..

<b:if cond='data:blog.pageType != &quot;archive&quot;'>
Hii this is an non archive page
</b:if>


Displaying something on post page only

<b:if cond='data:blog.pageType == &quot;item&quot;'>
Hii this is a post page
</b:if>


Displaying something on non post page only

<b:if cond='data:blog.pageType != &quot;item&quot;'>
Hii this is a non post page
</b:if>

 

Displaying something on static  pages only

<b:if cond='data:blog.pageType == &quot;static_page&quot;'>
Hii this is a static page
</b:if>


Displaying something on  all other than static pages

<b:if cond='data:blog.pageType != &quot;static_page&quot;'>
Hii this is not a static page
</b:if>



You can use the conditional thing for the index type pages. But i don't find much use in that.

Now displaying something on a particular url only (may be a particular post page only or something like that)


<b:if cond='data:blog.canonicalUrl == &quot;The_Particular_Page_Url&quot;'>
this will be displayed on The_Particular_Page_Url only
</b:if>
(you will have to replace The_Particular_Page_Url with the url where you need the widget to be displayed..)

Now displaying something on all pages other than a particular url

<b:if cond='data:blog.canonicalUrl != &quot;The_Particular_Page_Url&quot;'>
this will not be displayed on The_Particular_Page_Url
</b:if>


Now how to use two conditions (or more).. the logical AND thing.. :)

<b:if cond='data:blog.canonicalUrl != &quot;The_Particular_Page_Url1&quot;'>
<b:if cond='data:blog.canonicalUrl != &quot;The_Particular_Page_Url2&quot;'>
this is not Particular_Page_Url1 and this is not Particular_Page_Url2
</b:if>
</b:if>


the else thing..
What if you need to display something on the homepage and something else on all other pages.. here comes the use of if else

<b:if cond='data:blog.canonicalUrl == data:blog.homepageUrl'>
This is the homepage
line1
line2
<b:else/>
This is not the homepage
line 3
line4
</b:if>


Different combinations are possible..

Limitations
1) I don't see a way to use OR conditions
2) There isn't any direct easy way to include AND in conditional statements
3) The main drawback is that we cant enclose an entire widget within the b:if tag.. you will get some message telling that a b:section cant have b:if s ie you can wrap an unexpanded widget within a b:if condition


Wrapping a widget with the conditional tags
Every widget other than the BlogPost Widget has this general structure

<b:widget id='something' locked='' title='' type=''>
<b:includable id='main'>
somethings here
</b:includable>
</b:widget>


Wrapping conditional tags can be done as

<b:widget id='something' locked='' title='' type=''>
<b:includable id='main'>
<b:if cond='data:blog.canonicalUrl == &quot;The_Particular_Page_Url&quot;'>
some things here
</b:if>
</b:includable>
</b:widget>


this code will display the widget on The_Particular_Page_Url only (you have to provide this url)

Another Limitation..
wrapping the blogpost widget is little complicated as it has many b:includables.. yea you can do that too.. :)

Another Important B:if condition..

Some of you might want to display adsense ads below the first post only..OK there is a condition for checking if the post is the first post or not..
<b:if cond='data:post.isFirstPost'>
OH yea this is the first post on this page
</b:if>
This condition will work within the blogger post loop.

Comments

  1. this is very good hack i have added a cht widget using this hack.........

    ReplyDelete
  2. Thanks for the very useful article brother! I'll try to use it on my blog :)

    ReplyDelete
  3. I am trying to figure out how to display a particular widget on say... 5 different pages.. Is this at all possible?

    When you specify a specific URL to display a widget on this can only be done for 1 post. I have certain widget ADS I want displayed on certain pages but then not on others...

    The only way I can figure out is to use the "don't display widget on certain URLs" function but then I have to enter every single page that I don't want the widget display on.

    ReplyDelete
  4. @J-bone as i mentioned in the post blogger doesn't have any OR AND functions that means we cant use a function like(if it is ur1 or url2 or url3 or url4)

    but you still can write it by using the b if statement 5 times...
    <b:if cond='data:blog.url == &quot;url1&quot;'>
    widget code
    </b:if>
    <b:if cond='data:blog.url == &quot;url2&quot;'>
    the same widget code
    </b:if>
    similarly write 3 more b ifs for url3,url4 and url5

    ReplyDelete
  5. Ok, heres another question...

    I would like to display widgets based off post labels (tags). Is there anyway to do this. I played around with a bunch of different combinations for the "if" statement but couldn't find anything that would make it work.

    If this could be done it could be so powerful because I have TV, antenna, cell phones on my site and I want different widgets to show up on all of these different pages. If it could be done then I could base all the widgets off of labels and never have to go messing with already established widgets.

    Don't know if its possible though, I don't have much expertise in HTML or XML. Perhaps the information at the following URL would help...
    http://help.blogger.com/bin/answer.py?answer=47270

    ReplyDelete
  6. @J-Bone if you want to display something withing the BlogPost Widget(ie the post + comment part) then you can use the following code
    <b:loop values='data:post.labels' var='label'>

    <b:if cond='data:label.name == &quot;Blogger Widgets&quot;'>
    something to be displayed if the label matches
    </b:if>
    </b:loop>
    Here Blogger Widgets is the label name

    and i don't think that the same would be easily possible in the case of sidebar widgets..

    ReplyDelete
  7. you don't know of a way to do this for a widget that is not within the post? The widget I want to do this for will be placed in the top middel just before the post starts...? There's gotta be a way to do this but I just can't figure it out.

    ReplyDelete
  8. if it is just above the posts you can do it..
    <b:loop values='data:posts' var='post'> just put the code in my previous comment just below this one.. also dont forget to restrict the display of the same to item pages..

    This will display the widget above every post.. When you restrict it to item pages, it can be used as a widget just above your post.. hope this helps.

    ReplyDelete
  9. Aneesh,

    Thank you so much for your help. I was able to get different display ADS based off the labels for each post. This is huge because now I can determined what AD I want on each post based off of what label I give that post. Very simple and easy.

    I could not find this anywhere on the internet and usually can figure things out on my own but this was a tricky one.

    Thanks again!

    ReplyDelete
  10. @J-Bone thanks for the nice words.. :)

    ReplyDelete
  11. I don't know anything about these html and stuff. But I've used some of your other tips and they have been GREAT!

    Okay here's my ???, where do I go to insert these condition tags? Clueless...

    ReplyDelete
  12. @MochaTrina where do you want to display the widgett??
    if it is in the sidebar then use the selective code just below

    <div id='sidebar-wrapper'>
    <b:section class='sidebar' id='sidebar' preferred='yes'>

    use any of the first 10 codes that i have given..
    the rest may be complicated for you..

    ReplyDelete
  13. wow great think that used for make template go better. blogger can look better with this trick.

    thanks for share. absolutly I use some of this :D

    ReplyDelete
  14. be nice to build magazine style template for blogger :) thanks for the trick.

    regards,
    riez

    ReplyDelete
  15. Wow you helped me so much thank you very much!!!!!!

    John

    ReplyDelete
  16. Hay Can U help me? I Just wanna SHow My Widget on post but when i try it For Blog archieve..., It doesnt work, N the Just Show up this word : b:if must terminated by end tag <-- LIke that .. Please help me. Somebody?

    ReplyDelete
  17. Hi!

    I want to make a blog like this web site: http://www.mediafax.ro/. It's possible in blogger?

    How to make in label page other post with read more?

    How to make in home page more categoris with one post with read more and others posts only with title?

    You know a link where I can learn the structure of blogger template?

    Thanks

    ReplyDelete
  18. @Anonymous,
    its not impossible
    are you talking of something similar to the label pages of my blog? - you can implement it using Post Summaries by Blogger.

    yea to set up a home page like that you will have to use your logic and use the conditional tags effectively.. For your herlp i have added an additional tag to the post. that will help you..

    ReplyDelete
  19. @Aneesh,

    You are my hero!

    ReplyDelete
  20. @Aneesh,

    In home page, each post must go in his category:

    Post1, Post3, Post8, Post9, => Category1/Label1
    Post2, Post4, Post5, Post6 => Category2/Label2
    Post7, Post10, Post11, Post13 => Category3/Label3
    ....

    In each category, the first post must have a summary (read more..) + thumbnail, and the others posts only links:

    Category1

    Title Post1

    Text: bla, bla, bla, ...

    Read more

    Link to Title Post3
    Link Title Post8
    Link to Title Post9


    Category2

    Title Post2

    Text: bla, bla, bla, ...

    Read more


    Link to Title Post4
    Link Title Post5
    Link to Title Post6
    ....

    I don't know how to do that!

    Thanks!

    ReplyDelete
  21. @Anonymous ,
    my recent posts with thumbnails gadget can display latest posts from a praticular label.. Some modification to the script will allow you to show summary for the first post only..

    Then you can use the same widget for other categories..
    But i can't help you with this.. you will have to figure it out by yourself :).. i can just give you the tips.. :)

    ReplyDelete
  22. oh sir aneesh,now i can make my codes shorter with this..really thanks to u!!! now i no more need to add url one by one and luggish my codes,hahaha..this is really a great blog forum!!

    ReplyDelete
  23. If you read the docs the pageType widet parameter SHOULD provide this functionality. It has been reported MANY times since Dec 2006.. http://groups.google.com/group/bloggerdev/browse_thread/thread/7231da3d848743d9.

    It this was fixed and exposed to the general user base (GUI not templates), Blogger blogs would be MUCH cleaner, faster and easier to read.

    ReplyDelete
  24. i want to display a widget on posts of the same label and i tried that code you wrote in the comments but the widget didn't show up anywhere even in the label i selected or its posts here.
    i tried this on a widget in the footer and one in the header.
    i would really appreciate it if you told me how to do it.

    ReplyDelete
  25. Great!!! Thanks
    I was looking for
    if cond='data:post.isFirstPost'

    ReplyDelete
  26. i cant get a flash widget only to be on the home page. to check it out see www.techknow.net.tc thanks heaps thou this is a very good website!!

    ReplyDelete
  27. How do you display a particular widget on every page including the homepage?

    ReplyDelete
  28. @Anonymous
    isn't that what it normally does?

    ReplyDelete
  29. i need help..I have a read more code added in the html and the readmore button is now shown in the static pages too

    ReplyDelete
  30. @KeygenX - you have to wrap the thing in conditional tags like i have done for my automatic post summary script.Click here

    you have to figure it out from these two posts :)

    ReplyDelete
  31. I wanted to hide my chat box on the archive pages. . yet when i use the condition it doesn't work?why is that so?
    aside from that I also hide the same widget on a static page and on particular url.

    ReplyDelete
  32. Can you help me hide my "chatbox" widget(sidebar) on archive pages?
    Here's the link: http://pinoymoviexpress.blogspot.com .Please!

    ReplyDelete
  33. My wrong, I mistook the archive pages as with those of the "http://site.blogspot.com/search/label/animation?&max-results=21".How do i hide the chatbox in these kind of pages?

    on either "http://pinoymoviexpress.blogspot.com/search/" or "http://pinoymoviexpress.blogspot.com/search/label/".

    ReplyDelete
  34. you can hide them from index pages.(index pages include homepge + the 2 type of pages that you specified in your previous comment)

    data:blog.pageType!= index can be used to display on all pages other home page,label pages and search pages.

    data:blog.url == data:blog.homepageUrl can be used to display it on homepage.

    Manipulate these according to your needs.

    ReplyDelete
  35. Oh my! "data:blog.pageType!= index" hid the whole widget on every page. . .LOL! Can you help me out?, I need to display the sidebar(chatbox)on the homepage,post pages,archive pages other than those aforementioned "pages" that I have specified(search & label pages,respectively).Thanks!

    ReplyDelete
  36. The comment box wont allow me to type in ampersands.
    do you see the code saying
    Displaying something on all other than static pages

    Copy that code edit it and change static_page to index

    That code will display it only on posts + Static pages + Archives.

    Now use one more code block to display it on Home page

    ReplyDelete
  37. Thank You Aneesh! And by the way, is it impossible to add meta tags on search and label pages? how?

    ReplyDelete
  38. Thanks a lot brother... This will help me

    ReplyDelete
  39. Hey, this advice is very helpful, but I'm having the hardest time disabling a basic text Widget (I don't want my copyright notice to show up on one specific page). I've tried out many of the methods outlined above but the best I can succeed at is turning the notice off everywhere. Please take a look at the code below and let me know what I'm doing wrong. Thanks a lot in advance!


    -----














    -----

    ReplyDelete
  40. blogger comment forms wont allow you to post codes.If you need contact me at the forum :)

    ReplyDelete
  41. hi anesh good tutorial here, but one thing wordpress have and bloggger not is the selective display on homepage.

    I mean just display posts of certain categories.. this would be useful cause if it can happen in blogger anyone could easily have unlimited number of pages, (hiding then from index) and showing only the important ones, or news or something like this...


    I tryed to figure out something from your code but nothing happens could u try it?

    I think would be nice not just for me but for the whole blogger community.

    thanku for the attention

    ReplyDelete
  42. this is actually what I'm looking into... thanks

    ReplyDelete
  43. MAN I MADE IT!!! http://ilovietrancie.blogspot.com/

    CHECK IT OUT... THE HOME PAGE IS THE NEWS CATEGORY!! ALL THE POSTS IN OTHER CATEGORIES IS NOT SHOWN!!!

    VERY EASY MAN... JUST PUT 2 SECTIONS IN THE POST WIDGET ONE FROM THE POST USING THE


    He will not show the posts in the index page
    at the second widget in the second section just put a redirection java script to the category u want..

    and this xml code:



    he will check if it is the home and if it is he will redirect to the category you want.

    Many Thanks mate for the codes!!

    Now we can do as wordpress...

    ReplyDelete
  44. @Ruben Marcus Luz Paschoarelli - you are just redirecting the home page to that particular label page. that would be the best option.It is possible to remove other category posts from homepage.But it will be more like hiding the other category posts.So if no posts were posted to that category lately, then home page would appear empty..

    ReplyDelete
  45. I wonder if it possible to use selective display somehow to put different headers on different static pages in blogger. I am thinking about different custom image headers. I am not sure whether the PageID in the source code would address the page, and where I would put the code so that it would work in the header area.

    Or could one make a full-sized header widget somehow that gets positioned up in the header area over top of the regular one?

    ReplyDelete
  46. @Laurie - you can use the second last B:if condition to achieve that
    data:blog.url == "The_Particular_Page_Url"

    ReplyDelete
  47. Aneesh, thanks for this tutorial.
    Actually i just want to eliminate sidebar in static pages.
    So what i did is put the "Displaying something on all other than static pages " code below "div id='sidebar-wrapper'" as adviced on your comment above. the "/b:if" i put it after all "b:widget" and just before "/b:section"

    When i try to save it show error msg

    "The widget with id HTML3 is not within a section (actual parent element is: b:if.) Every widget should be in a section."

    Do you have any idea ?

    ReplyDelete
  48. Hi Aneesh, regarding my comment before, i found the way by add the code by putting the sidebar-wrapper code in between the code you provided.

    Anyway i thought that the page size will become bigger (because no sidebar anymore) like your subscribe page, but its not.

    ReplyDelete
  49. please help me! I raplace some lines with this codes or insert them into the widget code?

    ReplyDelete
  50. haha thx for the info very useful in my blog = )
    www.t3iktai.com

    ReplyDelete
  51. i have my post topics organized using labels. when you pull up all posts under a specific label/topic, i want a new header to appear... one that is specifically designed to go with the topic.

    is it possible?

    i was thinking i could use the selective widgets to only show certain headers when certain posts are pulled up.

    -- serious noob here. please be simple. --

    ReplyDelete
  52. I have a question.
    Code:

    Hii this is an archive page


    Eror, because not archive. My theme have label. It is eror.


    Hii this is an archive page


    Can you help me ? thanks

    ReplyDelete
  53. I want to set a specific blog post to always be displayed on my homepage. I was thinking of using the if statement on the blog widget but to me it would seem that that would decide whether the blog post box will appear on the homepage and not the specific blog post. My main email is tsholmes88@gmail.com and I hope I am able to do this. My homepage is www.pcrtech.blogspot.com but the site I want to do this on is www.agdesignz.blogspot.com .

    ReplyDelete
  54. excellent post, very clear, easy to understand and also short enough for those who don't want to read a novel just to get some information ;)

    i have linked to your post on my blog: Choose the content to display on the different page types in Blogger

    ReplyDelete
  55. thanks for this helpful article sir. I just have some question, what if i want to modify or add some code to a posts with particular label.
    example, i want to modify the posts with label "gallery" so it'll appear at the item page the <data:post.body/> is at the top before the title.

    like this;

    <data:post.body/>

    <data:post.title/>
    <label><post author><timestamp> etc...



    hope you get it. please help me. thanks.

    ReplyDelete
  56. Share Buttonjs appear but instead of in a row it appears in a two column table form.

    ReplyDelete
  57. How do I make my slider widget display on ALL pages, mainly homepage and posts? all posts?

    ReplyDelete
  58. Nice post! i like it , I'll try to use it on my blog .

    ReplyDelete
  59. Very useful article ,..Thank you for sharing it.

    ReplyDelete
  60. hi Aneesh,
    i'm newbie about blogger. I have an case with my blog, but i can't solve that..
    .. i want to put 2 element/widget posting within my blog. the one is only show based on label name and the other one is as ussual. and the both i want to show in my homepage with same time.

    please help me!

    ReplyDelete
  61. How can i modify that that ads will show after 1st AND 2nd post?

    ReplyDelete
  62. Hi Aneesh,

    I'm using labels to hide certain scripts on certain pages based on this code you posted earlier in the comments: ( i had to take out the "<" in the comment to stop the code from disappearing)

    b:loop values='data:posts' var='post'>
    b:loop values='data:post.labels' var='label'>

    b:if cond='data:label.name == "Blogger Widgets"'>
    something to be displayed if the label matches
    /b:if>
    /b:loop>

    It works great, but I have ran into a problem. When the item I want to hide is not within the post section, it gives me a template error saying that 'posts' is not in dictionary ['blog']. Is there any hack or script or any way to get around this? I want to be able to hide some right sidebar sharing buttons I added under a new div I made in the !-- main -- section.

    You can see them here on the right: http://www.neonjelloevangelist.com/2008/01/traditional-thanksgiving-sausage.html

    ReplyDelete
  63. @Neon Jello Evangelist - yup this condition will work only within the post loop.

    You can use some JavaScript/css snippets to hide it(from the post loop)

    <script type="text/javascript">
    document.getElementById('blockid').style.display="none";
    </script>
    <style type="text/css">
    #blockid{display:none;}
    </style>

    Put this inside the condition and the block which you want to hide should have this id.
    eg:
    <div id="blockid">your buttons</div>

    ReplyDelete
  64. help plz!!!!!!
    i have this blog http://tdmckarunyam.blogspot.com/ ... and i have used an html gadget above the bog post gadget... i have selected the gadget to display only on the homepage... and it works.. but the problem is that though the gadget disappears on going to other pages it leaves a white background at its place...... how to remove it provide that i want to keep the white background for the gadget...
    If it is not possible is ther a way that i can remove the gap between that html gadget and blog posts so that the white rectangle wont be a problem...

    ReplyDelete
  65. dude i tried the one that show the thing on all other pages except the homepage.

    the code + your code go something like this:
    <b:if cond='data:blog.url != data:blog.homepageurl'><script type="text/javascript">
    function getYpipePP(feed) {
    document.write('<ol style="">');
    var i;
    for (i = 0; i < feed.count ; i++)
    {
    var href = "'" + feed.value.items[i].link + "'";
    var pTitle = feed.value.items[i].title;
    var pComment = " \(" + feed.value.items[i].commentcount + "\)";
    var pList = "<li>" + "<a href="+ href + '" target="_blank">' + pTitle;
    document.write(pList);
    document.write(pComment); //to remove comment count delete this line
    document.write('</a></li>');
    }
    document.write('</ol>');
    }
    </script>
    <script src="http://pipes.yahoo.com/pipes/pipe.run?
    YourBlogUrl=http://www.arcx13.com
    &ShowHowMany=10
    &_id=390e906036f48772b2ed4b5d837af4cd
    &_callback=getYpipePP
    &_render=json"
    type="text/javascript"></script>
    </b:if>

    but the widget keeps showing on all pages including the homepage. what should i do?

    ReplyDelete
  66. @ARC- adding b:if codes as the widget code(content of html javascript gadget) wont work. The b:if codes will work only inside the template code. I guess that's where you went wrong.

    ReplyDelete
  67. btw, tried it once again and still, nothing. here's my code


    <b:if cond='data:blog.url != data:blog.homepageUrl'> <b:include name='quickedit'/>
    </b:includable>
    </b:widget>
    <b:widget id='HTML5' locked='false' title='Cerita Hangat' 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:if>

    ReplyDelete
  68. is it possible to selectively show a widget only in posts where TWO labels are present, at the same time?
    I need to show a widget only in post that have BOTH label2,
    but, even if I'm familiar with conditional tags, I'm struggling with this :-(

    it's easy to show that widget in every post with label1
    AND
    in every post with label2,
    but what I want is the intersection of them,
    can you please help me? thanks!

    ReplyDelete
  69. doesn't work for gadgets :/

    ReplyDelete
  70. great,
    its a gloueous inteligence of yours thik tank
    keep it up
    its a very helpful to me , i saved url of this post

    ReplyDelete
  71. aneesh,

    is it possible to allow/ show comments only for a particular page? i'm thinking of creating a static page and use the page to display only "comments". the page is meant for visitors to discuss/ feedback to me like a forum. i only need to allow/ show comments only for that particular page, other pages and posts shouldnt have comments. anything like that?

    ReplyDelete
  72. Good One... Helped me a lot... Thanks for sharing

    ReplyDelete
  73. Hi,

    I'm applying hide post from my homepage with this trick using .post{display: none;}. But there is one problem,
    You see, i have a post with 5 or more iframe (set as new post). Although, the homepage didn't show post page but the loading time is still too long. And when i set other post (that has only text) as new post, the homepage loading become faster. Although the post page is hidden but it doesn't prevent the post itself from loading in the background.

    How can i prevent the hidden post from loading on the homepage? Can i use JQuery? need example. Thanks..

    ReplyDelete
  74. I searched for hours for a way to display some code on my homepage only and finally found the solution here. Thanks a lot for this post, you are a life saver. I've bookmarked this page and will be visiting your site more often.

    ReplyDelete
  75. i want to hide all the post from home page
    How to hide post page in my blog?

    ReplyDelete
  76. Is there a way to do:
    if url1 then
    content-for-url1
    else if url 2 then
    content-for-url2
    else
    default-content

    http://milindblog-hobee.blogspot.com

    ReplyDelete
  77. I'm applying hide post from my homepage with this trick using .post{display: none;}. But there is one problem,
    You see, i have a post with 5 or more iframe (set as new post). Although, the homepage didn't show post page but the loading time is still too long. And when i set other post (that has only text) as new post, the homepage loading become faster. Although the post page is hidden but it doesn't prevent the post itself from loading in the background.

    How can i prevent the hidden post from loading on the homepage? Can i use JQuery? need example. Thanks..

    ReplyDelete
  78. <data:post.body/> is the tag which renders the post body.So you can just wrap this inside a conditional tag.

    ReplyDelete
  79. Hey. What I want is a textboxes in between my header and post bodies that displays conditionally based on whether a label is present in the blog post. I currently have such textboxes which show up when one clicks on the label archive here: progressiveproselytizing.blogspot.com click on "Politics" Say. I want that box to instead appear whenever a am reading a post with the label politics.

    Now in the comments above you indicated code that could do conditionals based on the label but only strictly INSIDE the post widget and not in a separate widget. However, it seemed that you were implying if the widget was directly above the posts it would work. If so, can you explain further or suggest another work arround?

    ReplyDelete
  80. @bazie - you will have to mess around with your html code for that.
    here is an easier solution.
    Add the following code above </head>
    <style type="text/css">
    #HTML2{display:none;}
    </style>
    <b:if cond='data:blog.pageType == "index"'>
    <script type="text/javascript">
    if (location.href.indexOf("/search/label/Politics") != -1)
    document.getElementById('HTML2').style.display="block";
    </script>
    </b:if>

    ReplyDelete
  81. Thanks for your reply!

    Hmmm, I am not sure that is quite it. I want the textbox to display on POST pages (above the post) when that post has a certain label, not to have it display on the index page for a certain label. The latter I already have (the box displays its content when the url is ...../label/politics and uses the #HTML2{display:none;} line to hide itself when the url is anything different).

    So my rough idea is that it would have to be a conditional that only occurred on pagetype "item", and then searched through the labels of that blogpost item to see if it matched. The problem being that my HTML2 widget can't access the data for the post.

    ReplyDelete
  82. @bazie - hide HTML2 using CSS.
    now make the selector visible, if the post has that label.
    you can use the following code in the post loop.

    <b:loop values='data:post.labels' var='label'>
    <b:if cond='data:label.name == "Politics"'>
    <script>
    document.getElementById('HTML2').style.display="block";
    </script>
    </b:if>
    </b:loop>


    and yea you should wrap this into another b:if tag so that it renders only on item pages.

    ReplyDelete
  83. it worked - thank you so much!

    Your willingness to engage with users really sets your website apart. twittered and stumbled.

    ReplyDelete
  84. @bazie - thank you for the kind words :)

    ReplyDelete
  85. Okay so solving this created another problem related to formatting on IE. I now have a series of HTML widgets above my blog post that get hidden or displayed based on labels and a few other things. It works great in Chrome and Firefox, but in IE (a bunch of versions) it leaves a blank space for each hidden widget with a small dot in the top left. As such, when I have a bunch of widgets there is a big empty space between my header and my blog posts.

    Now I have discovered conditional tags, and realize one can use these in the head to change, say, margins for widgets. However, I havn't been able to quite figure out how to do a conditional tag for IE that eliminates the blank space left by the hidden widgets. Any suggestions?

    If this can't be done with margins, I would also be okay with simply not having the text widgets in IE and only having them in firefox/chrome, however I can't seem to get these conditional tags working anywhere else outside of the head so the hidden widgets still display the blank space.

    Alternatively, if there was a way to, in the blog post section, to write content into a single widget that was conditional on data in the blog post. This way instead of having many different widgets, I would just have one the content of which was determined by the blogpost widget. However, I don't know if this is possible.

    Thanks so much

    ReplyDelete
  86. @bazie - the dot is due to the ieretrofit javascript which is used to render shadows and rounded corner in IE.
    The js is rendered using the all head content. If you want to remove it, then replace
    <b:include data='blog' name='all-head-content'/>
    with
    <meta expr:content='"text/html; charset=" + data:blog.encoding' http-equiv='Content-Type'/>
    <meta content='true' name='MSSmartTagsPreventParsing'/>
    <meta content='blogger' name='generator'/>
    <link expr:href='data:blog.homepageUrl + "favicon.ico"' rel='icon' type='image/x-icon'/>
    <link expr:href='data:blog.url' rel='canonical'/>
    <data:blog.feedLinks/>
    <b:if cond='data:blog.url == data:blog.homepageUrl'>
    <link href='http://www.blogger.com/openid-server.g' rel='openid.server'/>
    </b:if>

    ReplyDelete
  87. @bazie -
    <b:if cond='data:blog.searchLabel == "Politics"'>
    </b:if>

    This is the best way to do it :) you can use it outside the post loop. So now you know what is to be done :)

    ReplyDelete
  88. I tried showing widgets on some of the static pages, but I am nto able to do it!
    Since the content and the widget will come inside post-body!
    I tried implementing the code above post-footer.
    Its a labels widget!
    But when I save the template it throws an error! bX-lw6ujl
    Which it asks me to go and check in Blogger help which doesnt have any solution! Whats your help for me in this?

    ReplyDelete
  89. Hi Blogger Plugins, I'm looking for a way to create a script for one of my labels displayed only in a specific static page. What I try to do is create a static page amd named "News" and all post with the label "News" are displayed in this static page. I do not know much about blogger so I ask your help Blogger Plugin. (PD: my english sux too!)

    ReplyDelete
  90. Hi,
    I wanted to get the full code for the same comment by 'bazie' above.
    Eg, say I have a label 'music' and I want to display a particular gadget, say 'Text1', on all the posts under that label. The gadget should appear on the url '/search/label/Music' as well as on all the pages individually that have the 'music' label.

    Can you help with the full code? Thanks in advance.

    ReplyDelete
  91. @Ranjan - This post will give you an idea of where you have to add the condition

    http://www.bloggerplugins.org/2009/06/creating-separate-archive-page-or.html

    If you are still not able to make it out, use my Contact Form.

    ReplyDelete
  92. I have messaged you as I couldn't find the answer.

    ReplyDelete
  93. This tutorial is really help me, thanks.

    ReplyDelete
  94. Thank you, these codes are very useful for me

    ReplyDelete
  95. Thank you, these codes are very useful for me.

    ReplyDelete
  96. I tried selective display in my blog. But it shows a small box in the place of gadget. It looks like something not loaded. How can I hide the box?
    See my blog http://el-dorado-theartgallery.blogspot.com

    ReplyDelete
  97. To hide the empty widget box...

    Put the conditional tag after
    and immediately before

    enter the following code

    <
    style type='text/css'>
    #WidgetID {display:none;}


    (Replace the Widget Id from
    )

    It's working fine, but not with Blog archive

    ReplyDelete
  98. The above comment is not the original one... some important texts which I entered missing... kindly remove the two comments above by "Sivakamy"...no use

    ReplyDelete
  99. @Sivakamy - if you want to post html tags in this comment form, then you will have to escape them. For example < should be changed to &lt;
    > can be changed to &gt;

    ReplyDelete
  100. Thank you, I successfully implemented the above code on my blog.

    ReplyDelete
  101. How do you make the widget appear on ALL pages?

    ReplyDelete
  102. Old post but still very useful, thanks!

    Maybe it can be useful to know that x OR y = NOT(NOTx AND NOTy)
    but I don't really sure it can works out :D

    ReplyDelete
  103. Looks like this is answered here but still unsure. I have a twitter widget but I just want it to appear on the home page. is it here I'd edit and what exactly would I add:

    ReplyDelete
  104. hats of to you...man i love you.....i respect coders as i am also a java coder...

    1 thing i want to say that you are just


    awesome

    ReplyDelete
  105. hello sir...
    thanks for share this great tutorial.

    i just want ask. how if i want to selective display on /search?updated-max=2012-02-23T12:28:00%2B07:00&max-results=7

    cause, that is static date if i have new post. what the conditional tag/code for URL like that.

    thanks for your attention. sorry my english bad.

    ReplyDelete



  106. something to be displayed if the label matches



    i want to show specific widgets to posts with specific tags but its not working...

    ReplyDelete
    Replies
    1. that's a tricky one and can be done if you are trying to display something near to the post content based on the labels associated with the post. Forums or the Contact form will be the best place for this query as the Blogger comment form won't allow you to post code easily :-)

      Delete
    2. I sent you a message via contact form...I wish to find the solution to th problem....

      Delete
  107. Thanks for this post. Most of my problems were solved after I went through the post and was able to radically redesign my blog.

    ReplyDelete
  108. i have different types of ad codes.i want to display one ad in home page , and while viewing posts i want to display another ad code .how can this to be done help me

    ReplyDelete

Post a Comment