I'm looking to make the front page of my Jekyll site have the most recent post followed by links to the 3 or so other most recent posts. I would have thought that this would do so:
<!-- first post -->
{% for post in site.posts[1..3] %}
<!-- link to posts -->
{% endfor %}
How can I get the second through fourth posts?
Try this:
{% for post in site.posts limit:3 offset:1 %}
<!-- link to posts -->
{% endfor %}
Related
I am using Github Pages' Jekyll integration. I added the Disqus configuration today but Disqus does not appear on my posts. I have added the Disqus script to a file _includes/disqus.html and added {% include disqus.html %} to _layouts/default.html.
You may view this work at my https://github.com/shaneoston72/shaneoston72.github.io
Thank you for any help you can offer.
Ok, we'll need to do a few things here:
At the end of your file _layouts/default.html what I see is:
</div>
{% include disqus.html %}
{% include footer.html %}
</body>
Replace this part for:
</div>
{% include footer.html %}
{% if page.comments %}
{% include disqus.html %}
{% endif %}
</body>
Then, on your file _includes/disqus.html, delete the first and the last line:
{% if post.comments %}
.....
{% endif %}
This should do the job. Let me know how it goes, ok?
Hope to have helped!
I created a landing page for my octopress website and I'd like to have the most recent blog post displayed on the home page, but just the most recent blog. I am not sure quite how to proceed. Is there a code like {% include post %} that will allow me to do this?
Thanks.
As per usual, I tend to find the solution after I ask it.
On home page:
<div class="blog-index">
{% assign post = site.posts.first %}
{% assign content = post.content %}
{% include custom/asides/recent_post.html %}
</div>
In separate document saved to custom/asides/recent_post.html:
<h2 class="entry-title">
{% if post.title %}
{{ post.title }}
{% endif %}
</h2>
<div class="entry-content">{{ content | excerpt }}</div>
<a class="btn btn-default" href="{{ root_url }}{{ post.url }}">{{ site.excerpt_link }}</a>
Found solution here: https://gist.github.com/nimbupani/1421828
I can't find a solution. I have three categories: tuts, news, code.
The newest post is categorized in tuts. But I want to show the last and newest post in news. I tried the following, but obviously it doesn't show anything, because if I limit the loop to the first item, which is the tuts item, the loop stops.
{% for post in site.posts limit:1 %}
{% if post.categories contains 'news' %}
NEWS</strong> › {{ post.title }}
{% endif %}
{% endfor %}
How do I show the first posting from a special category? Can I loop directly through a chosen category like this? If yes, what is the correct syntax?
{% for post in site.posts.categories.news limit:1 %}
NEWS</strong> › {{ post.title }}
{% endfor %}
Yes, it's possible to directly loop all posts for a certain category or tag.
It's just:
{% for post in site.categories['news'] limit:1 %}
{{ post.title }}
{% endfor %}
It's the same for tags, you just have to replace site.categories['news'] by site.tags['news'].
I establish my Blog with the help of jekyll bootstrap and deploy it on github. Here is my question:
I want to add a sidebar which lists my newest 10 posts. When I use the code below, it lists all my posts:
<ul>
{% for post in site.posts %}
li>{{ post.title }}</li>
{% endfor %}
</ul>
BUT, I only want to list the newest 10 posts(if the num of all posts less than 10, list all),how can I do?
Thank You for your answer!
I don't have the environment to test it, but you might want to try limit keyword, see documentation here. I assume it will show all if limit is not reached.
<ul>
{% for post in site.posts limit:10 %}
<li>{{ post.title }}</li>
{% endfor %}
</ul>
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.
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>
{{ post.title }}
</li>
{% endfor %}
</ul>