Tags Jekyll post计数特定于定制前台事务
在过去的几个小时里,我与其他令人惊叹的Jekyll教程网站一起搜索了stackoverflow的深度,但还没有找到解决这个问题的方法=[ 我没有使用site.tags或site.categories,而是在类别“blog”下创建了自己的名为“subcategories”的自定义标签。目标是尝试获取每个类别的帖子数。我发现的教程对类别和标签都非常有效,只是没有自定义的前端内容 我的一些子类别是这样写的:Tags Jekyll post计数特定于定制前台事务,tags,yaml,jekyll,liquid,yaml-front-matter,Tags,Yaml,Jekyll,Liquid,Yaml Front Matter,在过去的几个小时里,我与其他令人惊叹的Jekyll教程网站一起搜索了stackoverflow的深度,但还没有找到解决这个问题的方法=[ 我没有使用site.tags或site.categories,而是在类别“blog”下创建了自己的名为“subcategories”的自定义标签。目标是尝试获取每个类别的帖子数。我发现的教程对类别和标签都非常有效,只是没有自定义的前端内容 我的一些子类别是这样写的: [design] [gaming] [design, gaming] 我正在寻找一个代码,当
[design]
[gaming]
[design, gaming]
我正在寻找一个代码,当它意识到有一篇文章包含子类别时,会将文章计数增加1。因为我没有使用插件,子类别的完整列表实际上在data.yml文件中单独列出(除了我的文章的开头)
以下是我写这篇文章的一次可怜的尝试:
<ul class="blog__sidebar__subcategories m-t-s">
{% for subcategory in site.data.subcategories %}
<a class="blog__sidebar__subcategories__item" href="{{ site.baseurl }}/blog/{{ subcategory.class }}">
<li>{{ subcategory.class }}
{% assign counter = '0' %}
{% assign subcat_data == site.data.subcategories %}
{% for post in site.categories.blog %}
{% if subcat_data == post.subcategories %}
{% capture counter %}{{ counter | plus: '1' }}{% endcapture %}
{% endif %}
{% endfor %}
({{ counter }})
</li>
</a>
{% endfor %}
</ul>
下面是我的.yml文件的外观(简单):
和我的代码,然后再尝试添加帖子计数(有效!):
{%用于site.data.subcategories%}
{%endfor%}
另外,如果我不小心违反了stackoverflow的社交礼仪,请告诉我。第一次发帖!非常感谢。Jekyll在用户数组方面做得不好。我认为你最好坚持使用Jekyll现有的机制 因此,您可以对子类别使用标记
---
layout: post
date: 2014-08-14 07:51:24 +02:00
title: Your title
categories: [ blog ]
tags:
- design
- gaming
---
你的循环可以是
{% for tag in site.tags %}
{% comment %}+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tag = Array [
"design",
Array [
#Jekyll:Post @id="/blog/1993/02/08/index",
#Jekyll:Post @id="/blog/1991/08/14/index"
]
]
Values in this tag array are :
- tag[0] -> "design"
- tag[1] -> an Array of posts that have the design tag
Here, we can already do a "{{ tag [0] }} : {{ tag[1] | size }}"
that will give us the count for each tag's posts array.
But if one post insn't in "blog" category but has a tag used
in the "blog" category, it will be counted here.
Where must count only posts that are in the "blog" category.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++{% endcomment %}
{% assign counter = 0 %}
{% for post in tag[1] %}
{% if post.categories contains "blog" %}
{% assign counter = counter | plus: 1 %}
{% endif %}
{% endfor %}
{% comment %}+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Only print counter if the current tag has "blog" posts
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++{% endcomment %}
{% if counter > 0 %}
<p>{{ tag[0] }} : {{ counter }}</p>
{% endif %}
{% endfor %}
{%for site.tags%}
{%comment%}+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
标记=数组[
“设计”,
排列[
#杰基尔:Post@id=“/blog/1993/02/08/index”,
#杰基尔:Post@id=“/blog/1991/08/14/index”
]
]
此标记数组中的值为:
-标记[0]->“设计”
-标签[1]->具有设计标签的一组帖子
在这里,我们已经可以做一个“{tag[0]}:{{{tag[1]|size}}”
这将为我们提供每个标记的posts数组的计数。
但是如果一篇文章不属于“博客”类别,但使用了标签
在“博客”类别中,它将在此处计算。
其中必须仅统计“博客”类别中的帖子。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++{%endcomment%}
{%assign counter=0%}
{%用于标记[1]]中的post
{%如果post.categories包含“blog”%}
{%分配计数器=计数器|加:1%}
{%endif%}
{%endfor%}
{%comment%}+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
仅当当前标记有“博客”帖子时才打印计数器
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++{%endcomment%}
{%如果计数器>0%}
{{tag[0]}}:{{counter}
{%endif%}
{%endfor%}
Hi here!Yowza,效果很好。我也注意到了使用前置内容过滤的插件的效果(尽管我更喜欢不使用插件)。插件和您的解决方案都工作得非常好!非常感谢您的帮助。我想在此期间我会祈祷用户阵列在Jekyll中发挥更好的作用?
<ul class="blog__sidebar__subcategories m-t-s">
{% for subcategory in site.data.subcategories %}
<a class="blog__sidebar__subcategories__item" href="{{ site.baseurl }}/blog/{{ subcategory.class }}">
<li>{{ subcategory.class }}</li>
</a>
{% endfor %}
</ul>
---
layout: post
date: 2014-08-14 07:51:24 +02:00
title: Your title
categories: [ blog ]
tags:
- design
- gaming
---
{% for tag in site.tags %}
{% comment %}+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tag = Array [
"design",
Array [
#Jekyll:Post @id="/blog/1993/02/08/index",
#Jekyll:Post @id="/blog/1991/08/14/index"
]
]
Values in this tag array are :
- tag[0] -> "design"
- tag[1] -> an Array of posts that have the design tag
Here, we can already do a "{{ tag [0] }} : {{ tag[1] | size }}"
that will give us the count for each tag's posts array.
But if one post insn't in "blog" category but has a tag used
in the "blog" category, it will be counted here.
Where must count only posts that are in the "blog" category.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++{% endcomment %}
{% assign counter = 0 %}
{% for post in tag[1] %}
{% if post.categories contains "blog" %}
{% assign counter = counter | plus: 1 %}
{% endif %}
{% endfor %}
{% comment %}+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Only print counter if the current tag has "blog" posts
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++{% endcomment %}
{% if counter > 0 %}
<p>{{ tag[0] }} : {{ counter }}</p>
{% endif %}
{% endfor %}