Liqiud basics
Modules
API
Mailer
Articles
On this page
Overview
Articles can be used to create a blog where you have different pages for each blog post (article), and you can show all blog posts (articles) in a archive. These archives can be sorted by the date that they were published, and they can also be sorted in monthly and yearly archives.
Below you can see all the available drops on the articles object. These drops are for multiple articles.
| Name | Description |
| articles.all | All articles |
| articles.paginate | All articles paginated. Requires a limit eg. articles.paginate.20 |
| articles.monthly_archive | Generate a monthly archive. Returns an Array with ArticleArchiveDrop objects |
Below you can see all the available drops on the article object. These drops are for a single article.
| Name | Description |
| article.id | The unique id |
| article.seo | SEO drop for this article |
| article.title | Article title |
| article.title_or_default_title | The article title for the current locale or default locale (see note) |
| article.url | Article URL |
| article.url_original | Article URL (same as above) |
| article.published_at | Publish date, comes in YYYY-MM-DD-HH-MM-SS GMT format |
| article.preview | The preview image associated with the article |
| article.preview_text | Preview text |
| article.preview_text_or_default_preview_text | Preview for the current locale or default locale (see note) |
| article.excerpt | Get the article excerpt (raw text) |
| article.content | Article content. This should not be used in articles.single.tpl |
| article.content_or_default_content | Article current locale content or default locale content (see note) |
| article.published_content | Get the published content from the editable |
| article.saved_content | Get the saved content from the editable |
| article.categories | Array with article category objects |
| article.category_names | Get a string with names to assigned categories |
| article.tags | Array with article tags |
| article.products | Array with Products in the article |
| article.account | Array with account object belonging to the user that created the article |
| article.account.full_name | Gives you the full name on the account that created the article |
In order for article.account and article.account_full_name to work the account needs to be a user on the site you're working on. Otherwise it will return nothing
When using a drop that has _or_default_content e.g. article.content_or_default_content the system will return the default locale (language) text for that drop.
So if you have a site in two languages: Swedish and English where Swedish is the default locale and there is no content in the English article it will fall back to the default locale (in this case Swedish).
articles.all
Basic usage for articles. Automatically sorts by newest article.
Get 10 articles
{% for article in articles.all.10 %}
<article>
<h2>{{ article.title }}</h2>
<div>
{{ article.content }}
</div>
</article>
{% endfor %}
Don't forget to add a limit!
articles.paginate
Use articles.paginate when you want to display a specific number of articles per page. You have to choose how many articles to display per page by adding a limit eg. 10 in the example below.
To be able to use the pagination you also have to include liquid tags. In those liquid tags you can choose which text should be displayed in the pagination button. In the examples below the text is "Newer" and "Older" but it could be anything you want.
Display 10 articles per page with pagination buttons
{% for article in articles.paginate.10 %}
// Code for displaying the articles
{% endfor %}
<button>{{ 'Newer' | paginate_previous_link }}</button>
<button>{{ 'Older' | paginate_next_link }}</button>You can only have one pagination per page. Also, don't forget to add a limit!
articles.monthly_archive
On articles.monthly_archive you can use the following drops
| Input | Output |
| month.year | e.g. "2013" |
| month.month | eg. "December" |
| month.url | e.g "/a?date=2013-11" |
| month.count | Number of articles within this month |
Monthly archive that displays name of month and year and generates a link
You can replace "month" with any word you want.
<ul>
{% for month in articles.monthly_archive %}
<li><a href="{{ month.url }}">{{ month.month }} - {{ month.year }}</a></li>
{% endfor %}
</ul>
Archive menu
The first level being the archive year and the second level being the archive month.
<div>
{% for frame in articles.monthly_archive %}
{% unless year == frame.year %}
{% unless year == '' or frame.year == year_now or frame.year == next_year %}
</ul></li>
{% endunless %}
{% assign year = frame.year %}
{% unless frame.year == year_now %}
<li>
<span>{{ frame.year }}</span>
{% unless frame.year == year_now %}
<ul>
{% endunless %}
{% endunless %}
{% endunless %}
<li>
<a href="{{ frame.url }}">
{{ frame.month }} {{ frame.year }}
</a>
</li>
{% endfor %}
{% unless year == '' or frame.year == year_now %}</ul></li>{% endunless %}
</div>Updated: 2019-12-05