DownloadNp Blog

How to exclude a category from homepage in Blogger

First, make a backup copy of your template.
Open your template.

Locate:
<b:if cond="data:mobile == "false"">
<!-- posts -->

Just below replace this code (there may be small differences in your template but the block is this):

<div class='blog-posts hfeed'>

      <b:include data='top' name='status-message'/>

      <data:defaultAdStart/>
      <b:loop values='data:posts' var='post'>
        <b:if cond='data:post.isDateStart'>
          <b:if cond='data:post.isFirstPost == &quot;false&quot;'>
            &lt;/div&gt;&lt;/div&gt;
          </b:if>
        </b:if>
        <b:if cond='data:post.isDateStart'>
          &lt;div class=&quot;date-outer&quot;&gt;
        </b:if>
        <b:if cond='data:post.dateHeader'>
          <h2 class='date-header'><span><data:post.dateHeader/></span></h2>
        </b:if>
        <b:if cond='data:post.isDateStart'>
          &lt;div class=&quot;date-posts&quot;&gt;
        </b:if>
        <div class='post-outer'>
        <b:include data='post' name='post'/>
        <b:if cond='data:blog.pageType == &quot;static_page&quot;'>
          <b:include data='post' name='comment_picker'/>
        </b:if>
        <b:if cond='data:blog.pageType == &quot;item&quot;'>
          <b:include data='post' name='comment_picker'/>
        </b:if>
        </div>
        <b:if cond='data:post.includeAd'>
          <b:if cond='data:post.isFirstPost'>
            <data:defaultAdEnd/>
          <b:else/>
            <data:adEnd/>
          </b:if>
          <div class='inline-ad'>
            <data:adCode/>
          </div>
          <data:adStart/>
        </b:if>
      </b:loop>
      <b:if cond='data:numPosts != 0'>
        &lt;/div&gt;&lt;/div&gt;
      </b:if>
      <data:adEnd/>
    </div>

with:

<b:if cond='data:mobile == &quot;false&quot;'>

    <!-- posts -->
    <div class='blog-posts hfeed'>

      <b:include data='top' name='status-message'/>

      <data:defaultAdStart/>
      <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 != &quot;computer&quot;'>
<div class='date-header'>
  <h2 class='date-header'>
<script type='text/javascript'>var ssyby=&#39;<data:post.dateHeader/>&#39;;</script>
   <h2 class='date-header'><span><script type='text/javascript'>document.write(ssyby);</script></span></h2>
</h2>
</div>
      <b:include data='post' name='post'/>
   
      <b:if cond='data:post.includeAd'>
          <b:if cond='data:post.isFirstPost'>
            <data:defaultAdEnd/>
          <b:else/>
            <data:adEnd/>
          </b:if>
          <div class='inline-ad'>
            <data:adCode/>
          </div>
          <data:adStart/>
      </b:if>
      </b:if>
      </b:if>
       
      </b:loop>
    </b:if>
</b:if>
<b:if cond='data:blog.pageType == &quot;static_page&quot;'>
  <div class='post'><h3><data:post.title/></h3></div> 
<div class='post'><data:post.body/></div>
<b:include data='post' name='postQuickEdit'/>

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

<b:if cond='data:blog.url != data:blog.homepageUrl'>
<b:if cond='data:blog.pageType != &quot;static_page&quot;'>

<script type='text/javascript'>var ssyby=&#39;<data:post.dateHeader/>&#39;;</script>
   <h2 class='date-header'><span><script type='text/javascript'>document.write(ssyby);</script></span></h2>
 <b:include data='post' name='post'/>
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<b:include data='post' name='comments'/>
      </b:if>
 </b:if> 
</b:if>
  </b:loop>

<data:adEnd/>
  </div>

In above code localize the row:
<b:if cond='data:label.name != &quot;computer&quot;'>

In my case the label I want to exclude from homepage is "computer" (red highlighted). You change it with what you want.

With this technique you'll have the date header on each post, also in post published on the same day.

Important: for a correct blog visualization this technique the user needs enabled javascript. Notice: give always a label to every post, otherwise this trick doesn't work properly.

No comments:

Post a Comment

Starter Template by pb