-
Notifications
You must be signed in to change notification settings - Fork 33
entries
Queries and returns entries based on the provided parameters.
When rendered, entries will be outputted using the layout specified in the entry's content type.
{{ entries(content_type='blog_post') }}
The output of entries can also be assigned to a variable and be used to generate inline markup:
{% set entries = entries(content_type='blog_post', paginate=15) %}
{% for entry in entries %}
<h3><a href="{{ entry.url() }}">{{ entry.title }}</a></h3>
<div class="post_detail">
{{ entry.created_at|user_date('j M Y') }}
| Posted by {{ entry.author() }}
</div>
<div>{{ entry.content }}</div>
{% endfor %}
<div id="pagination">
{{ entries.links() }}
</div>
Queries and returns a single entry by its id.
Used to return entries of a specified content type. To reference a content type supply the content type's short name.
content_type='pages'
To return entries of multiple content types, provide the list of short names separated by a pipe.
content_type='pages|events'
You can also return all entries but exclude entries of specific content types by using the keyword "not".
content_type='not pages|events'
Order the returned entries by a content type's content field. To set the order by, provide the fields short tag name without brackets.
order_by='title'
You can also order by multiple fields by providing a pipe delimited list of field short tags.
order_by='created_at|modified_at'
See the sort paramater on how to set the sorting for the order bys.
By default entries are sorted ascending. You can modify this by setting sort to "desc"
sort='desc'
If you have multiple order bys you can specify the sort for each order by with a pipe delimited list in the same order as the order bys.
sort='asc|desc'
Limit the number of entries returned.
limit=10
Offset is used in conjunction with limit and simply sets the query offset.
offset=5
Generates pagination for the entries query. the paginate argument should be set to the number of entries to show per page.
paginate=10
With pagination enabled several helper functions become available which can be called on the collection returned from the entries function:
- links()
- currentPage()
- lastPage()
- perPage()
- total()
- count()
- firstItem()
- lastItem()
- nextPageUrl()
- previousPageUrl()
- url(page)
- hasMorePages()
For example to show the pagination links use the links() function.
{% set pages = entries(content_type='pages', paginate=10) %}
{{ pages }}
{{ pages.links() }}
simple_paginate should be used rather than paginate if you only need to show next and previous links in your pagination view as it performs a more effiecient query.
simple_paginate=10
NOTE: With simple_paginate the pagination functions lastPage() and total() will not be available.
The where argument is very powerful in that it can generate complex and nested parameter grouping for the entries query where clause. This argument takes a JSON object or an array of JSON objects that contain the properties field, operator, value, and relation, however, only field and value are required as operator will default to '=' and relation will default to 'and'. The best way to understand what the where argument is capable of is to look at some examples:
where={field: 'title', value: 'Home'}
// This would generate something similar to the following clause:
// WHERE `title` = 'Home'
where=[
{field: 'content', operator: 'like', value: '%some text%'},
{field: 'content', operator: 'like', value: '%additional text%', relation: 'or'}
]
// This would generate something similar to the following clause:
// WHERE `content` LIKE '%some text%' or `content` LIKE '%additional text%'
where=[
{
nested: [
{field: 'title', value: 'Blog Post 1'},
{field: 'title', value: 'Blog Post 2', 'relation': 'or'},
],
},
{
nested: [
{field: 'content', operator: 'like', value: '%some text%'},
{field: 'content', operator: 'like', value: '%additional text%', 'relation': 'or'},
],
relation: 'or'
}
]
// This would generate something similar to the following clause:
// WHERE (`title` = 'Blog Post 1' OR `title` = 'Blog Post 2') OR (`content` LIKE '%some text%' OR `content` LIKE '%additional text%')
Available operators are:
- =, !=
- >, >=
- <, <=
- like, not like
- in, not in
- between, not between,
- is null, is not null
Filters entries by url_title.
url_title='blog-post-1'
Filters entries by creation year.
year=2016
To return entries from multiple years, provide the list of years separated by a pipe.
year='2016|2014'
You can also return all entries but exclude entries from specific years by using the keyword "not".
year='not 2016|2014'
Filters entries by creation month.
month=5
To return entries from multiple months, provide the list of months separated by a pipe.
month='5|12'
You can also return all entries but exclude entries from specific months by using the keyword "not".
month='not 5|12'
Filters entries by creation day.
day=25
To return entries from multiple months, provide the list of days separated by a pipe.
day='25|31'
You can also return all entries but exclude entries from specific days by using the keyword "not".
day='not 25|31'
Allows you to throw an http error code if no results are found. This is useful if you would like to show a 404 if no entries are found. The argument should be set to the error code you would like to throw.
no_results_abort=404