Django cms 教程十:完善最近文章列表

一、添加“OLDER POSTS”按钮

Clean Blog模板的首页除了4篇文章,还有一个"OLDER POSTS"的按钮链接,下面我们来看如何添加。

打开/templates/aldryn_newsblog/plugins/目录下的latest_articles.html,可以看到它的代码:

1{% load i18n %}
2 
3{% for article in article_list %}
4    {% include "aldryn_newsblog/includes/article.html" with namespace=instance.app_config.namespace %}
5{% empty %}
6    <p>{% trans "No items available" %}</p>
7{% endfor %}

从上面的代码我们可以看到,它通过for循环遍历我们的4篇文章,将这些信息传递给article.html。
用下面的代码:

1<div class="post-preview">
2    {% include "aldryn_newsblog/includes/article.html" with namespace=instance.app_config.namespace %}
3</div>

替换原有的:

1{% include "aldryn_newsblog/includes/article.html" with namespace=instance.app_config.namespace %}

并在最末尾添加如下代码:

1<!-- Pager -->
2<ul class="pager">
3    <li class="next">
4        <a href="#">Older Posts &rarr;</a>
5    </li>
6</ul>

添加后的效果:
Snap18405

二、修改样式

打开templates/aldryn_newsblog/includes下面的article.html,

{% render_model article "title" "" "" "striptags" %}

替换原来的:
{% render_model article "title" %}


{% render_model article "lead_in" "" "" "truncatewords:'20'|striptags" %}
替换原来的:
{% render_model article "lead_in" "" "" "truncatewords:'20'" %}

{% render_model article "lead_in" "" "" "striptags" %}
替换原来的:
{% render_model article "lead_in" %}
用:
{{ article.publishing_date|date:"F d, Y" }} 
替换原来的:
{{ article.publishing_date|date }}

替换之后的效果图:
Snap18410

三、修改OLDER POSTS链接
打开templates/aldryn_newsblog/plugins/ 下面的latest_articles.html,将第一行的代码改成:
{% load i18n apphooks_config_tags %}
然后用:

1<a href="{% namespace_url "article-list" namespace=instance.app_config.namespace default='' %}">Older Posts &rarr;</a>

替换原来的:

1<a href="#">Older Posts &rarr;</a>

Django cms 教程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值