I'm trying to show the top 3 blog posts in Jekyll. Using Jekyll bootstrap, I see that there is a layout for a post (a layout and an underlying theme page) - what I want to do is repeat that post layout for each of the posts.. Something like:
{% for post in site.posts %}
-- Render the post layout for this post.
{% endfor %}
I'm not sure how to do this without having to copy the content for the post layout, and either add it inside that for loop, or create a JB include, which still doesn't solve the problem 'cos I'll still have to copy and paste the post html markup.
Another reason for using Jekyll as your default hosting platform is that it's a lot fast than WordPress. Unlike WordPress, it won't crash when there's a lot of traffic on our website.
In the end, I realised that I don't need most of the markup from the post layout, so I took what I need and embedded this in the for loop..
{% for post in site.posts %}
{% include JB/post_content %}
{% endfor %}
and post_content
<article class="unit-article layout-post">
<div class="unit-inner unit-article-inner">
<div class="content">
<div class="bd">
<div class="entry-content">
{{ post.content }}
</div><!-- entry-content -->
</div><!-- bd -->
</div><!-- content -->
</div><!-- unit-inner -->
</article>
Yup. We ended up using a similar format:
<h3>Posts</h3>
<ul>
{% for post in site.posts %}
<li>
<a href="{{ post.url }}">{{ post.title }}</a>
</li>
{% endfor %}
</ul>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With