Liqiud basics
Modules
API
Mailer
Article categories
On this page
Overview
The article categories can be reached from any template, except from article_category.url (more info below).
Below you can see all the available drops on the article categories object
| Name | Description |
| article_categories.all | Returns an array with ArticleCategoryDrop objects (see below) |
Below you can see all the available drops on the article category object
| Name | Description |
| article_category.id | Unique id |
| article_category.name | Name of category |
| article_category.title | Title of category. Needs to be set in all locales |
| article_category.articles | Array with category articles |
| article_category.url | URL for the single category page |
| article_category.monthly_archive | Generate a montly archive Array |
| article_category.seo | SEO drop for the article category |
article_categories.all
Returns an array with all of the article categories.
Below is an example of how to display all category names. In order to use the url you are required to have the template article.archive.tpl
Loop through all categories
<ul>
{% for category in articles.article_categories.all %}
<li>{{ category.name }}</li>
{% endfor %}
</ul>
Fetch specific category
In the example "test" is the url of the category. So if you have a category named "Top rated movies" you should write article_categories.top-rated-movies
<ul>
{% for article in article_categories.test.articles.10 %}
<li>{{ article.title }}</li>
{% endfor %}
</ul>Filter articles by categories
Sometimes you want to show articles including or excluding certain categories.
For example you have articles with the category "Top secret" that you only want to show on a page that only authorized personal can see. Then you want to filter the articles based on the category "Top secret".
Get articles with one or more specific categories
In the example you will get articles that either have the category "categoryOne" or "categoryTwo". Or both.
{% for article in articles.only_categoryOne_categoryTwo.10 %}
<article>
<h2>
<a href="{{ article.url }}" title="{{ article.title }}">{{ article.title }}</a>
</h2>
<div>
{{ article.content }}
</div>
</article>
{% endfor %}
Get articles except articles with one or the other category
In the example you will get all articles except the ones that have the category "categoryOne" or "categoryTwo". Or both.
{% for article in articles.except2_categoryOne_categoryTwo.10 %}
<article>
<h2>
<a href="{{ article.url }}" title="{{ article.title }}">{{ article.title }}</a>
</h2>
<div>
{{ article.content }}
</div>
</article>
{% endfor %}
Get articles except articles containing all of the chosen categories
In the example you will get all articles except the ones that have both the category "categoryOne" or "categoryTwo". Or both.
{% for article in articles.except_categoryOne_categoryTwo.10 %}
<article>
<h2>
<a href="{{ article.url }}" title="{{ article.title }}">{{ article.title }}</a>
</h2>
<div>
{{ article.content }}
</div>
</article>
{% endfor %}
Note
The names categoryOne and categoryTwo are the url of the category that you want to exclude. Don't forget to add a limit, in the examples above the limit is 10.
Updated: 2019-12-12