Hiển thị bài viết thuộc một nhãn nhất định ở trang chủ

Posted by Tung Thanh Ly Vietnam on Friday, October 31, 2014 with No comments

Vào Thứ Sáu, tháng 9 05, 2014 Question | Subscribe | Member | Comments Trong thiết kế blog đôi khi theo yêu cầu bạn chỉ muốn hiển thị bài viết thuộc một nhãn nhất định ở trang chủ hoặc kiểu trang index, về cơ bản cách này ngược với cách ẩn bài viết thuộc một nhãn nhất định ở kiểu trang index.

 

 1. Đăng nhập vào blog của bạn.
2. Chọn mẫu (tempalate) => Chọn Chỉnh sửa HTML (Edit HTML)
3. Tìm đoạn code <b:includable id='main' var='top'> và kéo chuột xuống vài dòng bạn sẽ tìm được đoạn code tương tự như bên dưới (đoạn này có thể khác nhau tuỳ theo từng blog nha các bạn):

 

 

<b:loop values='data:posts' var='post'>
<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 cond='data:post.includeAd'>
<b:if cond='data:post.isFirstPost'>
<data:defaultAdEnd/>
<b:else/>
<data:adEnd/>
</b:if>
<data:adCode/>
<data:adStart/>
</b:if>
<b:if cond='data:post.trackLatency'>
<data:post.latencyJs/>
</b:if>
</b:loop>
 
 
  Thay thế nó thành đoạn code bên dưới:
 
 <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 == "Show Label"'>
<b:include data='post' name='printPosts'/>
</b:if>
</b:loop>
</b:if>
<b:else/>
<b:include data='post' name='printPosts'/>
</b:if>
</b:loop>
 
 
Ở đây Show Label, Chính là tên nhãn mà bạn muốn hiển thị bài viết của nhãn đó ở trang chủ.

- Lúc này mình tìm thẻ đóng </b:includable> của thẻ <b:includable id='main' var='top'>. Và đặt đoạn code bên dưới vào sau thẻ </b:includable> nói trên.

<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 == &quot;static_page&quot;'>
<b:include data='post' name='comments'/>
</b:if>
<b:if cond='data:blog.pageType == "item"'>
<b:include data='post' name='comments'/>
</b:if>
</b:includable>
 
 Lưu mẫu lại và kiểm tra kết quả của các bạn nha.