Blogger: Filter posts by label on your main page

I spent quit a while phishing around google trying to figure out how to prevent posts with a certain label from appearing on my main page over at blogger/blogspot. Eventually, I used an adaptation of this method (also detailed here).

To applay this method, edit your blogger sites XML template (be sure to back it up first!), and click "Expand Widget Templates". Now look for the line:

<b:loop values='data:posts' var='post'>

And find the matching </b:loop> tag.

Replace them and everything between them with the following code:

<b:loop values='data:posts' var='post'>
<b:if cond='data:blog.url == data:blog.homepageUrl'>
<b:if cond='data:post.labels'>
<b:loop values='data:post.labels' var='label'>
<b:if cond='data:label.isLast == &quot;true&quot;'>
<b:if cond='data:label.name != "Label_To_Filter">
<b:include data='post' name='printPosts'/>
</b:if>
</b:if>
</b:loop>
</b:if>
<b:else/>
<b:include data='post' name='printPosts'/>
</b:if>
</b:loop>

Now look for the last </b:includable> tag you can find, and paste this code directly after it:

<b:includable id='printPosts' var='post'>
<b:if cond='data:post.dateHeader'>
<h2 class='date-header'>
<data:post.dateHeader/>
</h2>
</b:if>
<b:include data='post' name='post'/>
<b:if cond='data:blog.pageType == "item"'>
<b:include data='post' name='comments'/>
</b:if>
</b:includable>

Note that this code has a few bugs:

  1. Posts with no label will not be displayed on the main page.

  2. The filtered label must be the last label of a filtered post.

  3. If all your recent stories belong to the filtered category, your blog may appear empty.


I consider these "Features" as they suit my need over at www.luxphile.com - preventing any of my Texture labeled posts from showing up on the main page, and also hiding unlabeled "Blog this" posts from Flickr.

33 comments:

  1. Hey man, this was a lifesaver. I used a modified version of it to make two columns of posts on the main page. The left column has the "left" tag and so on.

    ReplyDelete
    Replies
    1. Hello...

      Dear Applicant, I am Mr.Ben Dean Global Loan Film LTD.. We are an international loan firm. It a financial opportunity at your door step We provide Business and personal loans etc. as long as it concerns financial assistance..We are certified, trustworthy, reliable, efficient, fast and dynamic. And a Co-operate Financier For Real Estate And Any Kinds Of Business Financing Apply today and you will get a loan from us..
      * It a world of happiness with us bring back those joy of yours by applying for a loan with us today...

      All these plans and more, contact us now by email for more info.. (globalloanfilm@gmail.com)

      Giving your world a meaning.

      Delete
  2. Filtering Blogger Posts by Labels on Homepage

    I'm looking for something similar, but in the other direction: to only show posts with a certain combination of labels on the home page, eg: "question" + "featured".... I guess that would look something like this? (Very new to blogger customization - today, actually ; )


    b:loop values='data:posts' var='post'
    b:if cond='data:blog.url == data:blog.homepageUrl'
    b:if cond='data:post.labels'
    b:loop values='data:post.labels' var='label'
    b:if cond='data:label.name = "Question"
    b:if cond='data:label.name = "Featured"
    b:include data='post' name='printPosts'/
    /b:if
    /b:if
    /b:loop
    /b:if
    /b:if
    /b:loop

    ReplyDelete
  3. Hi, I'm hoping you could help me. I would love to make this work on my blog, but when I try to save the template edits, I get this message:

    XML error message: The value of attribute "cond" associated with an element type "null" must not contain the '<' character.

    Not sure what it means. I am using one of the new blogger standard templates with some customizations (background, widgets, bannner).

    Any advice would be really appreciated!!

    Thanks!

    ReplyDelete
  4. I get the same error message as tupelodogg. Doesn't work.

    ReplyDelete
  5. In case tupelodogg and motmaitre are still working with this the error is the result of a missing apostrophe. In the first block of code

    ReplyDelete
  6. Ah, it removed the code. Anyway the line with 'Label_to_Filter' in red, at the end of that, between the double quotes and the greater than sign should be a single quote

    ReplyDelete
  7. @Economic Perspectives From Kansas City - That helped so much, because I was getting that same error.

    However, now nothing is showing up and I only have one post in that "filtered" category so it's not like I have them all with it.

    Not sure what went wrong here...

    SEO Domain Names

    ReplyDelete
  8. In case tupelodogg and motmaitre are still working with this the error is the result of a missing apostrophe. In the first block of code

    kapıda ödemeli alışveriş

    ReplyDelete
  9. should i replace all codes with or replace the first block only? coz i find several codes start with

    ReplyDelete
    Replies
    1. *with b:loop values='data:posts' var='post'

      Delete
  10. I am getting this error:Error parsing XML, line 2320, column 2: The value of attribute "cond" associated with an element type "b:if" must not contain the '<' character.

    Please help!

    ReplyDelete
  11. Is there any alternative of this as of now.. not working on me..

    Please Help
    JelBee.com

    ReplyDelete
  12. I just gave this a shot, and now no posts are visible on my Home page or on my link pages. :(

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Woops that comment got messed up I pasted it here check it out:

    http://justpaste.it/ftc8

    ReplyDelete
    Replies
    1. Thanks a lot for this! I couldn't get the code from the original post to work but your code worked on the first try. Really appreciate it.

      Delete
    2. OMG, thanks a lot Stunna, i was searching for this code more than a month, and just your, just your code really works without destroy my template.. really thanks

      Delete
  15. Thanks you very much. I applied on my blog.

    ReplyDelete
  16. Can you help me pls, I want to filter more than one label

    ReplyDelete

  17. Do you need a quick long or short term loan with a relatively low interest rate as low as 3%? We offer business loan, personal loan, home loan, auto loan,student loan, debt consolidation loan e.t.c. no matter your credit score. We are guaranteed in giving out financial services to our numerous clients all over world. With our flexible lending packages, loans can be processed and transferred to the borrower within the shortest time possible, contact our specialist for advice and finance planning. If you need a quick loan contact us via Email: williamsmr504@gmail.com

    ReplyDelete
  18. BENEFITS GIVEN TO NEW
    MEMBERS WHO WILL JOIN
    FREEMASON & ILLUMINATI.
    A
    1.Cash Reward of USD $
    980,000
    2.A New Sleek Dream CAR
    valued at USD $850,000
    3.A Dream House bought in the
    country of your own choice
    One Month holiday (fully
    paid) to your dream tourist
    destination.
    One year Golf Membership
    package
    4.A V.I.P treatment in all
    Airports in the World
    5.A total Lifestyle change
    Access to Bohemian Grove
    One Month booked
    Appointment with Top 5
    world Leaders and Top 5
    Celebrities in the World.
    call this number to join +2348134548904 or email on illuminatiorderworlwide@gmail.com

    ReplyDelete
  19. Are you in need of a loan? Do you want to pay off your bills? Do you want to be financially stable? All you have to do is to contact us for more information on how to get started and get the loan you desire. This offer is open to all that will be able to repay back in due time. Note-that repayment time frame is negotiable and at interest rate of 3% just email us (urgentloan22@gmail.com)

    ReplyDelete
  20. I am posting this AD as part of my promises to GT LOANS 48. kindly contact them today for a loan via email: gtloans48@gmail.com Company Mobile number: text 1 (802)851-7538.

    ReplyDelete
  21. Good day, here comes an easy way to become a member of the world famous {Illuminati} brotherhood. For the working class, business men / women, artists, politicians who want to be bigger, more powerful and more influential in the world, join us in becoming one of our official members today. You will be given an ideal opportunity to visit the Illuminati circle after you complete the registration, no sacrifice or human life is needed, the Illuminati brotherhood brings protection, power, wealth and fame in life. You have full access to eradicate the poverty of your generation. Only an existing member of the Illuminati circle has the authority to introduce any member to the circle. So before contacting us, You must be 18 years or older and once you become a member you will be entitled to all benefits for the rest of your life. So if you are ready to become a member, sign up for the official Illuminati WhatsApp [+2348110562645] Email (Illuminatitemple395@gmail.com

    ReplyDelete
  22. Maybe because you've not met the right person to help you join Illuminati Brotherhood or you have the benefit of doubt that Illuminati Brotherhood is not real, hear me now, this testimony is for you.
    8 years ago, I happened to fall countless victim of scam but I didn't give up until luck may have it, I came across a genuine member of the Illuminati Brotherhood who assisted me through in the process of joining Illuminati brotherhood. I'm a proud member of the Illuminati Brotherhood and I'm also willing to render help to whosoever is willing to join the Illuminati Brotherhood. The good news is, Registration is free for new members that want to join.
    Do you desire to become a Warlock, Vampire or a werewolf then simply follow up with the contact info on this testimony because the Illuminati Organization is a Society that actualize it's members dreams and wishes no matter how impossible it sounds.
    Are you looking for fame, protection or wealth then do yourself good and join Illuminati Brotherhood so you can receive your benefits to build the life of your dream. Simply WhatsApp/Message or Call +1 (202) 750-0111 or email churchofilluminatiinitiation@gmail.com.
    Good luck as you apply to join the Illuminati Brotherhood free of charge.

    ReplyDelete
  23. ATTENTION TO ALL, ILLUMINATI HAS BECOME WHAT PEOPLE IN DIFFERENT COUNTRY USE TO MAKE MONEY INSTEAD OF HELPING THE POOR THEY NOW TAKE FROM THE POOR BROTHERS AND SISTERS OUT THERE WHO ARE WILLING TO JOIN THIS ORGANIZATION SHOULD BE AWARE OF WHO THEY CONTACT BEFORE SENDING YOUR INFORMATION TO ANY BODY YOU MUST HAVE TO BE CAREFUL BECAUSE WE ARE GETTING SO MANY CONPLAIN FROM NEW MEMBERS I KNOW HOW I SUFFERED BEFORE JOINING THIS ORGANIZATION DONT GIVE UP AM HERE TO HELP THE POOR,THE TALENTED,THE BUSINESS MEN AND WOMEN,TO REACH THEIR GOALS SO FOR MORE INFORMATION ON HOW TO JOIN CALL this number OR WHATSAPP him ON SAME NUMBER also +1 (202) 750-0111 YOU CAN STILL SEND him MESSAGES ON THIS EMAIL

    initiationlodgeofilluminati@gmail.com

    ReplyDelete