【问题标题】:Listing all the blog posts (with content) with Jekyll使用 Jekyll 列出所有博客文章(包含内容)
【发布时间】:2012-03-20 20:49:31
【问题描述】:

我正在尝试展示 Jekyll 中排名前 3 的博客文章。使用 Jekyll 引导程序,我看到有一个帖子的布局(一个布局和一个底层主题页面) - 我想要做的是为每个帖子重复该帖子布局.. 类似于:

  {% for post in site.posts %}
    -- Render the post layout for this post.
  {% endfor %}

我不确定如何在不必复制帖子布局的内容的情况下执行此操作,或者将其添加到 for 循环中,或者创建一个 JB 包含,这仍然不能解决问题“因为我”我仍然需要复制并粘贴 post html 标记。

【问题讨论】:

    标签: jekyll


    【解决方案1】:

    最后,我意识到我不需要帖子布局中的大部分标记,所以我把我需要的东西嵌入到 for 循环中..

    {% for post in site.posts %}
    {% include JB/post_content %}
    {% endfor %}
    

    和 post_content

    <article class="unit-article layout-post">
        <div class="unit-inner unit-article-inner">
            <div class="content">
                <div class="bd">
                    <div class="entry-content">
                        {{ post.content }}
                    </div><!-- entry-content -->
                </div><!-- bd -->
            </div><!-- content -->
        </div><!-- unit-inner -->
    </article>
    

    【讨论】:

      【解决方案2】:

      是的。我们最终使用了类似的格式:

      <h3>Posts</h3>
      <ul>
        {% for post in site.posts %}
        <li>
          <a href="{{ post.url }}">{{ post.title }}</a>
        </li>
        {% endfor %}
      </ul>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-08-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多