Improve your experience at WBO. You should consider allowing javascript, cookies and loading of external resources from third-party sites.

Added a list of recent articles on WBO

A small new feature on WBO was added, the list of 5 last articles, displayed under the menu. Once again, Django does it so easy.

Just create a new file named article_tags.py in the folder templatetags of the article application.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from django.template import Library

from ..models import Article

register = Library()

@register.inclusion_tag('article/tags/recent_articles.html')
def get_recent_articles(number=5):
    articles = Article.published.all()[:number]
    return {'articles': articles,}

Add the template (recent_articles.html) in subfolder tags of the article application:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<span class="menu_section_title">Recent articles</span>
<ul>
    {% for article in articles %}
    <li class="with-disc">
        <a href="{{ article.get_absolute_url }}">
          <span class="menu_articles_title">{{ article.title }}</span>
      </a>
    </li>
    {% endfor %}
</ul>

And the stuff is ready to use. In a template, just load the article tags and use the new tag:

1
2
3
4
{% load article_tags %}
<div id="recent_articles" class="menu_section">
   {% get_recent_articles %}
</div>

Now I'm starting to work on a hierarchical tree of articles. Stay wired on WBO for new adventures with Django and especially with regroup tag !!

back to top