[英]repeating html for post excerpt in jekyll
i am migrating my website made with php and wordpress in jekyll. 我正在jekyll中迁移用php和wordpress制作的网站。 everything is going smooth except for some problems i'm having with the blog section.
一切都进行得很顺利,除了我在博客部分遇到的一些问题。
here what my blog/index.html looks like: 我的blog / index.html如下所示:
---
layout: posts
---
{% for post in paginator.posts %}
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
<p>
<span class="date"><i class="fa fa-date"></i> {{ post.date | date: "%m-%d-%Y"}}</span>
</p>
{{ post.excerpt }}
<a class="more-link" href="{{ post.url }}">Read more...</a>
{% endfor %}
what i would like to happen is that the html of the layout: posts repeats for every {{ post.excerpt }} i have. 我想发生的是布局的html:帖子对我拥有的每个{{post.excerpt}}都重复一次。 instead, it just wraps all post excerpt into that single html bit.
取而代之的是,它将所有摘要摘录都包装到该单个html位中。 here's the layout:
这是布局:
<div class="page-container">
<div class="sub-container blog">
<h1>Blog</h1>
<div class="entry">
{{ content }}
</div>
<!-- Pagination links -->
<div class="pagination">
<ul>
{% if paginator.previous_page %}
{% if paginator.previous_page == 1 %}
<li>
<a href="/blog/">Prev</a>
</li>
{% else %}
<li>
<a href="/blog/{{ paginator.previous_page }}">Prev</a>
</li>
{% endif %}
{% else %}
<li>
<span class="disabled">Prev</span>
</li>
{% endif %}
{% if paginator.page == 1 %}
<li>
<span class="active">1</span>
</li>
{% else %}
<li>
<a href="/blog/">1</a>
</li>
{% endif %}
{% for count in (2..paginator.total_pages) %}
{% if count == paginator.page %}
<li>
<span class="active">{{ count }}</span>
</li>
{% else %}
<li>
<a href="/blog/{{ count }}">{{ count }}</a>
</li>
{% endif %}
{% endfor %}
{% if paginator.next_page %}
<li>
<a href="/blog/{{ paginator.next_page }}">Next</a>
</li>
{% else %}
<li>
<span class="disabled">Next</span>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
is there a for loop i have to create with post excerpts? 我必须用摘要来创建for循环吗? what's the syntax?
语法是什么? i have no idea how to achieve this.
我不知道如何实现这一目标。
thanks! 谢谢!
Why did you put your loop with excerpt in one file and pagination in an other ? 为什么您将带有摘录的循环放在一个文件中并将分页放在另一个文件中?
This post template will only be used by blog index and pagination pages, so you can merge everything in your blog/index.html
and do : 该帖子模板仅由博客索引和分页使用,因此您可以合并
blog/index.html
并执行以下操作:
---
layout: default
---
<div class="page-container">
<div class="sub-container blog">
<h1>Blog</h1>
<div class="entry">
{% for post in paginator.posts %}
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
<p><span class="date"><i class="fa fa-date"></i> {{ post.date | date: "%m-%d-%Y"}}</span></p>
{{ post.excerpt }}
<a class="more-link" href="{{ post.url }}">Read more...</a>
{% endfor %}
</div>
<!-- Pagination links -->
<div class="pagination">
<ul>
... pagination code here
</ul>
</div>
</div>
</div>
actually i just needed to move the opening and the closing of the for-loop outside div.entry
like so: 实际上,我只需要将
div.entry
外的for循环的打开和关闭移动如下:
{% for post in paginator.posts %}
<div class="entry">
<h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
<p>
<span class="date"><i class="fa fa-calendar"></i> {{ post.date | date: "%m-%d-%Y"}}</span>
</p>
{{ post.excerpt }}
<a class="more-link" href="{{ post.url }}">Read more...</a>
</div>
{% endfor %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.