Adding Featured Posts
<!--
Everything is pulled together by adding this to relevant layouts
-->
{% if page.feature.visible == true %}
{% include featured.html %}
{% endif %}
# To display on a page, the following YAML Front Matter is added — customizing the headline and assigning a site.categories category to pull from.
feature:
visible: true
headline: "Featured Tutorials"
category: mastering-paper
<!--
The first step is to flag a post as featured. To do this, I add featured: true to its YAML Front Matter.
Next I use a variation of the related posts include with additional Liquid conditionals to control headlines and other variable data.
/_includes/featured.html
-->
<h3 class="tile__header">{% if page.feature.headline %}{{ page.feature.headline }}{% else %}Featured Posts{% endif %}</h3>
<div class="tiles">
{% assign features = site.categories[page.feature.category] | where:"featured", true %}
{% for post in features limit:3 %}
<article class="tile__item" itemscope itemtype="http://schema.org/CreativeWork">
<meta itemprop="text" content="{{ post.excerpt | strip_html }}">
<a href="{{ post.url }}">
<img src="{% if post.image.teaser %}{{ post.image.teaser }}{% else %}{{ site.teaser }}{% endif %}" itemprop="image" alt="{{ post.title }}">
<h3 class="tile__title" itemprop="headline">{{ post.title | markdownify | remove: '<p>' | remove: '</p>' }}</h3>
{% assign readtime = post.content | strip_html | number_of_words | divided_by:site.words_per_minute %}
<span class="tile__item-time">{% if readtime <= 1 %}1{% else %}{{ readtime }}{% endif %} min read</span>
</a>
{% if post.work %}
<span class="tile__category">{{ post.work }}</span>
{% endif %}
</article>
{% endfor %}
</div>