How to Prevent Certain Post Labels from Displaying on the Main Blog Feed

 
How to Prevent Certain Post Labels from Displaying on the Main Blog Feed


Did you know that you can prevent certain posts from landing on the main feed?


I ran into a situation where I needed to do just that.

In one of my recent blog redesigns I wanted to highlight the photos that I post on it and also have a page that is dedicated to actual blog posts for SEO purposes. With this style of 'blog' I only wanted the photos to display on the main page and not the posts that are labeled blog.


To edit your blog to prevent certain labels from displaying on the main blog feed you need get down and dirty with the HTML editor. As always, be sure to back up your template before you edit.

To begin, go to Template -> Edit HTML, this page will show all your code for your blog. You then must find a specific line of code to edit. Press CTRL+F to find:

<b:include data='post' name='post'/>

And replace it with this:

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

What exactly does it do?


What this code does is check if the current page's url is the same as the main feed pages url.

It then loops through every posts labels and questions if that was the last label of that post and checks if any of that posts labels != does not match "LABEL NAME HERE". If the post doesn't match the label, it will then include that post on the home page.

NOTE: In order for this to work, you must only have one label!

Once all the posts are looped through, if the home page wasn't chosen it will display any post regardless of the label name.

What if I want to block it from being searched or only directly linked to?


If you would like to only block the page from being shown on the main page and not search or label page then change this line:

<b:if cond="data:blog.url == data:blog.homepageUrl">

To this:

<b:if cond='data:blog.pageType == &quot;index&quot;'>

This code checks if the current page's pageType that you are on is an index type page (Home Page, Search Page or Label Page basically any page that isn't directly a blog post) instead of checking if the current page is the main pages url.

Why would I want to do this?


In my case, I have a photo based blog main page that just shows photos. On the 'blog post' pages I just have a short description of each with the photo. (Think foodgawker.com)

Short description pages do not rank well on Google search though because of low word counts and that's where the blog section will come in to play, long posts that focus on certain long tail keywords for improved search SEO for the website.

With this style of website, I do not want the blog labeled post to show up with the photos on the main screen; only when I hit the 'blog' button.

Why Blogger and Not WordPress?


People do not realize it, but what you can do in Blogger is truly amazing for a free blogging platform.

No sense in paying for a hosted WordPress site when you can do the exact same things on a free service.

Blogger does have it's limitations, which is a post for another day, but for most cases, blogger is perfect.



How to Prevent Certain Post Labels from Displaying on the Main Blog Feed How to Prevent Certain Post Labels from Displaying on the Main Blog Feed Reviewed by Chef M Kraft on 2/10/2017 Rating: 5

No comments:

Powered by Blogger.