html 显示按类别组织的帖子

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 显示按类别组织的帖子相关的知识,希望对你有一定的参考价值。

<!--
Following on the sorting technique above, for this docs site, the left nav is essentially a category name and then a list of the posts within that category. In the below code, I loop through the posts (sorted by weight) and display the category header assuming the post’s category is different from the prior post (of course, this assumes that the content is organized properly by weight).

One other thing you may notice is that I ignore posts with no title. In the case of my single page documentation site, some sections had “intro” text that would display in the content but doesn’t require a navigation link. Thus, if I left the title blank, I will display it in the main content output but not in the navigation. You can also see that I am using the post.slug variable as a way to anchor the links rather than directly link to the page.
-->

<ul class="docs-nav">
  {% assign posts_list = site.posts | sort:"weight" %}
  {% assign last_cat = "" %}
  {% for posts in posts_list %}
      {% if posts.title != "" %}
          {% for category in posts.categories limit:1 %}
              {% if category != last_cat %}
      <li><strong>{{ category | replace: "-", " " | capitalize  }}</strong></li>
              {% endif %}
              {% assign last_cat = category %}
          {% endfor %}
      <li><a href="#{{ posts.slug }}" class="cc-active">{{ posts.title }}</a></li>
      {% endif %}
  {% endfor %}
</ul>

以上是关于html 显示按类别组织的帖子的主要内容,如果未能解决你的问题,请参考以下文章