I am new to Jekyll. I know that Jekyll supports to show recent post with the following code:
<div id="recent-posts" class="recent-posts">
{% for this_post in paginator.posts %}
<div class="post">
<a href="{{ this_post.url }}">
<h2 class="post-title">{{ this_post.title }}</h2>
</a>
{% include category_info %}
{% include source_info %}
</div>
{% endfor %}
</div>
But I would like not to show a category of posts, saying the category name is "notshowing". How can I make it?
To avoid showing a specific category you can use the unless filter:
executes a block of code only if a certain condition is not met (that
is, if the result is false).
So for example, inside the for loop, use {% unless post.categories contains "notshowing"%}
In your example, using the site posts site.posts instead of paginator.posts (you can adjust that to fit what you need) it would look like:
<div id="recent-posts" class="recent-posts">
{% for post in site.posts %}
{% unless post.categories contains "notshowing"%}
<div class="post">
<a href="{{ post.url }}">
<h2 class="post-title">{{ post.title }}</h2>
</a>
</div>
{% endunless %}
{% endfor %}
</div>
Related
In the following code, I have a category by the name "ml" defined in my yml file frontmatter. For some reason, the {% unless cat == "ml" %} is not working properly. See this html, and the output image below. Clearly, the category is ml (I have tried to remove any whitespace with the strip filter, which did not work), but it is not working (the unless statement, that is).
Please help!
<div class="posts">
<h1>Recent Posts: </h1>
{% for post in paginator.posts %}
{% assign cat = post.categories %}
{% unless cat == "ml" %}
<div class="post">
<h1 class="post-title">
<a href="{{ post.url }}">
{{ post.title }}: {{ cat }}
</a>
{% if post.image %}
<img src={{post.image}}>
{% endif %}
</h1>
<span class="post-date">{{ post.date | date_to_string }}</span>
</div>
{% endunless %}
{% endfor %}
</div>
I still am not completely sure on the why here, but I found that using contains rather than == solved my issue.
having trouble nesting the following code. Where am I going wrong?
I just want to have some events show if the day is monday and then within that each event has a number of stars so I want to have another if statement that pulls that amount of stars and displays the correct image.
Here is my code.
<div class="row">
{% for event in site.nottingham_events %}
{% if event.day == "Monday" %}
<div class="event-guide-event">
<img class="event-guide-event--thumbnail" src="/img/thumb.jpg"
alt="">
<h2>{{ event.name }}</h2>
<p>When: {{ event.time }}</p>
<h3>Where: {{ event.bar }}</h3>
<h3>Hosted By: {{ event.brand }}</h3>
{% if event.stars =="3" %}
<img src="/img/events/3-stars.png" alt="Everyone">
{% endif %}
{% if event.stars =="2" %}
<img src="/img/events/2-stars.png" alt="Enthusiasts and
Beginners">
{% endif %}
{% if event.stars =="1" %}
<img src="/img/events/1-star.png" alt="Expert">
{% endif %}
</div>
{% endif %}
{% endfor %}
</div>
I resolved it by changing my logic, because you can't nest if statements in Liquid.
hello everyone i am new to github,jekyll and ruby and maybe this question is already answered but being a newbie it's hard for me to resolve the problem.
i am trying to put multiple paginations on a single page i.e. say i have two
authors posting their content on the blog so i created a division for each of them and want pagination for each of them individually.So the current code is something like this:
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
{% for post in paginator.posts %}
{% if post.author contains "NAME OF AUTHOR 1" %}
<div class="post-preview">
<a href="{{ post.url }}">
<h2 class="post-title">
{{ post.title }}
</h2>
<h3 class="post-subtitle">
{{ post.description }}
</h3>
</a>
<p class="post-meta">Posted by {{ post.author }} {{ post.date | date_to_string }}</p>
</div>
<hr>
{% endif %}
{% endfor %}
<!-- Pager -->
{% if paginator.total_pages > 1 %}
<ul class="pager">
{% if paginator.previous_page %}
<li class="previous">
← Newer Posts
</li>
{% endif %}
{% if paginator.next_page %}
<li class="next">
Older Posts →
</li>
{% endif %}
</ul>
{% endif %}
</div>
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
{% for post in paginator.posts %}
{% if post.author contains "NAME OF AUTHOR2" %}
<div class="post-preview">
<a href="{{ post.url | prepend: site.url }}">
<h2 class="post-title">
{{ post.title }}
</h2>
<h3 class="post-subtitle">
{{ post.description }}
</h3>
</a>
<p class="post-meta">Posted by {{ post.author }} {{ post.date | date_to_string }}</p>
</div>
<hr>
{% endif %}
{% endfor %}
<!-- Pager -->
{% if paginator.total_pages > 1 %}
<ul class="pager">
{% if paginator.previous_page %}
<li class="previous">
← Newer Posts
</li>
{% endif %}
{% if paginator.next_page %}
<li class="next">
Older Posts →
</li>
{% endif %}
</ul>
{% endif %}
</div>
Also under _config.yml paginate is set to 3.
I have used jekyll with bootstrap(if am correct not jekyll-bootstrap) and followed a pretty simple tutorial ,also the file structure is also very simple.
thanks for your help i have read many documentation and many posts(always bound to screwup) before posting this so thanks to everyone.
Also,
the blog is hosted at http://neorblog.in and github repositories at https://github.com/neortls007idev/Blog
Also the repo is not currently commited as per the above code.
Pagination is for all posts. You cannot have a pagination for posts where author == NeoR.
You still have the solution to create a generator plugin. And yes, github pages doesn't accept foreign plugin for security reasons.
But, simply pushing to github is not the only workflow available. You can try this.
I am trying to pull only the products from a collection that have a certain tag. This is my way of creating sub-collections since Shopify doesn't do this. My code doesn't seem to be working, and I can't figure out why it isn't working. I am doing this on the collection.liquid page. It is just printing the headings to the screen, but not the list of products. Any ideas?
{% if collection.handle == "all" %}
<!-- All Collections -->
<div id="collections">
<h2>Brave Bracelets</h2>
<div class="product-list clearfix">
<h3>Cerulean</h3>
<ul>
{% for product in collections.brave-bracelets.products %}
{% capture alt_attr %}{{ product.title }} by The Brave Collection{% endcapture %}
{% if product.tags contains "cerulean" %}
<li>
<img src="{{ product.featured_image | product_img_url: 'compact' }}" alt="{{ alt_attr }}" />
<h3>{{ product.title }}</h3>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div><!-- #collections -->
{% endif %}
There is a minor mistake on your capture line, which should be:
{% capture alt_attr %}{{ product.title }} by The Brave Collection{% endcapture %}
But other than that, your code worked fine for me. I pasted it into collection.liquid and changed the collection "brave-bracelets" and tag "cerulean" to a collection and tag of my own, and it displayed the list of products as expected. Maybe double check that you do have products with the tag "cerulean" in the collection "brave-bracelets"...
<section id="article">
<h3>Recent posts</h3>
<ul>
{% for post in site.posts %}
<li>» {{ post.title }}</li>
{% endfor %}
</ul>
</section>
This is my codes for all articles, how can I control the number of posts, and just show 10 posts in the section?
This is the way to do it.
{% for post in site.posts offset: 0 limit: 10 %}
<section id="article">
<h3>Recent posts</h3>
<ul>
{% for post in site.posts limit:10 %}
<li><a href="{{ post.url }}">
{% endfor %}
</ul>
</section>
Try this one. This code show 10 most recent post like recent post widget.
I'd go about it another way.
{% for post in site.posts limit:1 %}
{% if forloop.last %}
<li>
{{ post.title }}
</li>
{% endif %}
{% endfor %}
I've included an if logic tag with a forloop.last so it would only display the last, most recent post. The output would only be one post since I've also included { limit:1 }.