Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Getting latest news with findTaxonomy

Started by Muut Archive 10 years ago · 6 replies · 368 views
10 years ago

Hi,
I have a big archive of news (category = 'news') and I'd like to get last 10 news (more recents): what is the better method using findTaxonomy to use less resources? I dont't be able to order desc and limit results.
thanks

10 years ago

yes!
I have used:
taxonomy.findTaxonomy({'category':'news'})|reverse(true)|slice(filters tart,filterend)

thank you

10 years ago

Unfortunately this method does not consider order by date of news and I cannot use page.collection (i.e.page.collection({'items':{'@taxonomy.category': 'news'},'order': {'by': 'date', 'dir': 'desc'} }).slice(filterstart,filterend)) because this method takes only items of 'archives_year' or 'archive_month' param (note that I use archive plugin).

10 years ago

Ordering by date works if each page found in the taxonomy has the date-field set in its frontmatter, like date: 04-03-2016. I use the following loop in a current project:

TWIG
{% for page in taxonomy.findTaxonomy({'category':'news'}).order('date', 'desc').slice(0, 17) %}
{% endfor %}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1362 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2959 9 years ago
Archive · by Muut Archive, 9 years ago
3 1124 9 years ago