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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

List of "featured" articles

Started by Muut Archive 12 years ago · 15 replies · 316 views
12 years ago

I added a "featured" taxonomy, then in each article's .md file, I have:

YAML
taxonomy:
  featured: true

Is this right?

...Then what's the recommended way of going through the list (sorting by date) in a partial template?

👍 1
12 years ago

Yah that would work fine. Then in your template you could display the featured articles with:

TWIG
{% for featured in taxonomy.findTaxonomy({'featured':true}) %}
    <h1>{{ featured.title }}</h1>
    <p>{{ featured.content }}</p>
{% endfor %}
👍 1
12 years ago

Ok... And would it be possible, to do this without taxonomy? Assuming, that I have a custom field named "position", would it be possible to get only all files with "position: right" (or "position: left")?

12 years ago

Well it is possible, but it would mean you would have to loop over every page and look in each page's header for that position variable. That would be quite inefficient. Taxonomy is basically doing this and caching the results in a quick lookup table. So what your trying to do is what Taxonomy is built for.

12 years ago

Continuing my example... If I want to sort the articles in that list, I create, say, a "featured-weight" taxonomy. Then, e.g., in the first two featured articles' .md files, I have:

TXT
featured-weight: 100

and

TXT
featured-weight: 10

...And now how can I use this new taxonomy to sort them? I've checked, and this is not documented yet...

12 years ago

( Hum, I think featured-weight should be featuredWeight instead, right? )

12 years ago

BTW, a "sort by date" example (most recent first) would be great, too. Thanks!

12 years ago

Yah dashes are not valid variable characters, can be camel case featuredWeight or underscores featured_weight

The thing about taxonomy is that the values are stored and used to map to the article. This means that you can't really compare one against another to providing sorting.

There are a number of sort options available so perhaps you can use date combined with featured to get your desired result?

12 years ago

OK, so manual positioning isn't possible here?...

12 years ago

BTW, say that I want to hand pick 3 articles (from time to time) to be featured... Without having to copy/paste their info (which, in my case, is page.title, page.url, and a custom description), could I reference them somehow? This sort of thing can be quite useful...

12 years ago

It is possible to use manual ordering, and do what your asking with a taxonomy based collection. Read this section of the docs

This was tested in development and should work as advertised :)

12 years ago

OK, basically I have two kinds of lists, a "featured articles" one and a "latest articles"... I'll see if I can get it by reading the docs. :) Thanks!

12 years ago

...Meanwhile, please let me know if I can go the "hand pick 3 articles" route I mentioned above for the “featured articles” list...

12 years ago

You can use multiple taxonomies to filter more. Read the taxonomy docs to see how to use compound taxonomy queries.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1282 9 years ago
Archive · by Muut Archive, 9 years ago
2 889 9 years ago
Archive · by Muut Archive, 9 years ago
2 4019 9 years ago
Archive · by Muut Archive, 9 years ago
1 2894 9 years ago
Archive · by Muut Archive, 9 years ago
3 1078 9 years ago