Created
February 21, 2012 18:20
-
-
Save carolineschnapp/1877953 to your computer and use it in GitHub Desktop.
Pulling relevant articles from one blog in product.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% comment %} | |
Put the code below in a new snippet called relevant-articles.liquid. Include that snippet in product.liquid using {% include 'relevant-articles' %}. | |
Edit how many articles maximum you want to show by editing the how_many_articles_to_show variable assignment near the top. | |
Requirement: whenever you are blogging and you happen to say something that is relevant to product A or product B, add the title of those products as tags to your blog post. | |
For example, if you are writing about how you have been working on improving a product called 'Gizmo', then add 'Gizmo' as tag to your blog post. | |
{% endcomment %} | |
{% assign blog = blogs.news %} | |
{% assign how_many_articles_to_show = 3 %} | |
{% assign index = 0 %} | |
{% paginate blog.articles by 100 %} | |
{% for article in blog.articles %} | |
{% if article.tags contains product.title and index < how_many_articles_to_show %} | |
{% assign index = index | plus: 1 %} | |
<div class="article"> | |
<h4>{{ article.title }}</h4> | |
<div> | |
{% if article.excerpt.size > 0 %} | |
{{ article.excerpt }} | |
{% else %} | |
<p>{{ article.content | strip_html | truncatewords: 50 }}</p> | |
{% endif %} | |
<a href="{{ article.url }}">Read more →</a> | |
</div> | |
</div> | |
{% endif %} | |
{% endfor %} | |
{% endpaginate %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment