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 显示按类别组织的帖子的主要内容,如果未能解决你的问题,请参考以下文章

html 杰基尔:按类别排除帖子

WordPress:如何使用 $wp_query 按类别过滤帖子?

html 显示实际帖子类别的帖子

使用 ajax 通过 WordPress 菜单在 div 中按类别加载最新帖子

当数据按聚簇索引的顺序排列时,覆盖索引是不是有用?

使用 PHP 按类别过滤帖子