Best practice to set post as featured

Im making food blog and the home page will have one featured recipe on top. What is the practice to mark this post as featured in content file? If i make boolean in the front matter, I dont like that when I change to a new featured post, that I need to set isFeatured parameter to false for the old featured post.

Another way that I think of is puting it as a site parameter in config file. And to change this url when new post is featured. What I dont like about this idea, that as far as I know, I would need to change this in code. This is not a good solution for me, becouse this blog will be run by non-programer person.

So I’m looking for a good solution that featured post can be set from the forestry CMS.

I appreciate all of you guys that will help with this problem of mine.

have a great day

Set featured in front matter, but where you show the post in the theme template, only show the latest one (or however many you choose).

Or, set featured as a timestamp, and don’t show an article after that date; a form of “featured expiry”.

Great. I like the last idea. for a newbie like me this looks like a very clever approach

If you have a sense of how long a feature runs, you can set it in the archetype. I can’t find an example of what I was thinking, but you can draw inspiration from a thread that starts around Parsing dates in templates.

I imagine it adding 2 weeks to .Date or something. :slight_smile:

Here’s how I would do it.

  1. Create a file in your project’s data dir. Naming it something like editor-config.yaml.
  2. Then, from your forestry dashboard, create a Section of type Document which points to this file.
  3. From Forestry Front Matter, create a Front Matter Template (FMT) and add one Select Field. You can set a source for the options of the field, this will be Pages and the section… Recipes?
  4. For now, Forestry won’t let you assign the FMT to a Document section using their dashboard. But you can do it from their .forestry/ dir which lives at the root of your project.
    In .forestry/settings.yml find the Configuration section you created and add a template to it like so:
- type: document
  path: data/editor-config.yml
  label: Configuration
  templates:
  - editor-config #the name of your FMT ;)

Now, when visiting your Configuration section, the editor should see the select box (along with any other config field you may have added) and select the featured recipe which will always be unique. Plus you got yourself an “editor setting” section.

From your code, you’ll fetch those as any .Site.Data object.

I have not tested this but will for sure when the need comes, in the meantime, let me know if it worked for you!

Cheers,

1 Like