使用液体按字母顺序排列帖子 [英] Using liquid to sort posts alphabetically
问题描述
我现在有这样的东西:
$ b有没有一种方法来按字母顺序排序一些帖子$ b
{%for site.categories.threat%中的帖子}
< li>< a href ={{post.url}}> {{post.title}}< / a>< / li>
{%endfor%}
有用,但帖子混乱。如果按字母顺序排序,我认为它会更好看。
谢谢
可以在没有插件的情况下完成,这意味着它可以与 Github Pages 但是,您必须使用一些丑陋的字符串操作技巧。 同样的方法,稍微修改: 我在这个例子中使用了 如果您只想显示特定标签/类别(而不是所有帖子)中的帖子,您可以将 loop ( Is there a way to sort a number of posts alphabetically, using Jekyll? I have something like this now: It works, but the posts are jumbled up. Would look much nicer if they were sorted alphabetically I think. Thanks It can be done without a plugin, which means that it works with Github Pages. You have to use some ugly string manipulation tricks, though. Same approach, slightly modified:
You need two different separator characters inside the first loop (and of course again in the I'm using If you want to display only the posts in a certain tag/category (and not all posts), you can change the first
这篇关于使用液体按字母顺序排列帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
我使用了类似的方法要实现一个标签页(列出每个标签的所有帖子)。
{%capture posts%}
{site.posts%中的帖子%}
| {{post.title}}#{{post.url}}
{%endfor%}
{%endcapture%}
{%assign sortedposts = posts | split:'|'| sort%}
{%for postpostpostposts%}
{%assign postitems = post | split:'#'%}
< a href = {{postitems [1]}}> {{postitems [0]}}< / a>< br>
{
在第一个循环中需要两个不同的分隔符(当然在后面的
split
>调用中也是这样)
为了达到这个目的,这两个字符都不能出现在任何帖子标题或URL中!
|
和#
,这对我很有用(我刚测试过我的博客)。但是您可能需要使用不同的字符,具体取决于您的帖子标题以及您的网址是如何构建的。
奖励:
capture
中)中的第一个更改为这些:
<$ p $ %>
$ b {%for site.categories ['whatever']%}
{% for post in site.categories.threat %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
I used a similar approach to implement a tag page (that lists all posts for each tag).{% capture posts %}
{% for post in site.posts %}
|{{ post.title }}#{{ post.url }}
{% endfor %}
{% endcapture %}
{% assign sortedposts = posts | split: '|' | sort %}
{% for post in sortedposts %}
{% assign postitems = post | split: '#' %}
<a href={{ postitems[1] }}">{{ postitems[0] }}</a><br>
{% endfor %}
Beware:
split
calls later on).
In order for this to work, both characters must not occur in any of the post titles or URLs!!|
and #
in this example, which works for me (I just tested it with my blog). But you might need to use different characters, depending on your post titles and how your URLs are constructed.
Bonus:
for
loop (the one inside the capture
) to one of these:{% for post in site.tags['whatever'] %}
{% for post in site.categories['whatever'] %}