Blog
Perfect Latest Articles
Translated from: Django cms 教程十:完善最近文章列表
原载:蜗牛博客
网址:http://www.snailtoday.com
尊重版权,转载时务必以链接形式注明作者和原始出处及本声明。
1. Add “OLDER POSTS” button
Besides four articles, there should be a link of “OLDER POSTS” button on the home page of template Clean Blog.
Let's see how we add it.
Open latest_articles.html inside /templates/aldryn_newsblog/plugins/ you could see the following code:
{% load i18n %} {% for article in article_list %} {% include "aldryn_newsblog/includes/article.html" with namespace=instance.app_config.namespace %} {% empty %} <p>{% trans "No items available" %}</p> {% endfor %}
From the code above we could know, it goes through our for articles and sends those information to article.html via for loop.
Use the following code:
<div class="post-preview"> {% include "aldryn_newsblog/includes/article.html" with namespace=instance.app_config.namespace %} </div>
to replace
{% include "aldryn_newsblog/includes/article.html" with namespace=instance.app_config.namespace %}
And add the following code at the very end of the line:
<!-- Pager --> <ul class="pager"> <li class="next"> <a href="#">Older Posts →</a> </li> </ul>
The result should be like:
2.Modify the Style
Open article.html inside /templates/aldryn_newsblog/includes and adapt the following lines
from:
{% render_model article "title" %}
to:
{% render_model article "title" "" "" "striptags" %}
from:
{% render_model article "lead_in" "" "" "truncatewords:'20'" %}
to:
{% render_model article "lead_in" "" "" "truncatewords:'20'|striptags" %}
from:
{% render_model article "lead_in" %}
to:
{% render_model article "lead_in" "" "" "striptags" %}
from:
{{ article.publishing_date|date }}
to:
{{ article.publishing_date|date:"F d, Y" }}
The result should look like:
3.Modify OLDER POSTS Link
Open latest_articles.html inside templates/aldryn_newsblog/plugins/.
Replace the first line with {% load i18n apphooks_config_tags %}
Then, replace:
<a href="#">Older Posts →</a>
with:
<a href="{% namespace_url "article-list" namespace=instance.app_config.namespace default='' %}">Older Posts →</a>
Click here to download a PDF copy of this article
Save it to read later, or share with a colleague
Comment
There is no comment, you can make the first one!