我想在一个页面上显示一个内容条目(来自一种内容类型),并且我希望通过链接直接访问这个页面。
到目前为止,我已经创建了内容类型“post”(使用旅行车生成.)。它包含“标题”、“日期”和“正文”等字段。在" post“页面上,列出了文章的所有标题,当您单击其中一个标题时,应该重定向到包含其余内容的子页面”post“(取决于您选择的帖子)。
posts.liquid:
{% extends parent %}
{% block main %}
{% for post in contents.posts%}
<a href="/{{ post._slug }}"><li>{{ post.date }} - {{ post.titel }} </li></a>
{% endfor %}
{% endblock %}这列出了所有的帖子。
post.liquid:
{% extends parent %}
{% block main %}
<h2>{{post.title}}</h2>
<h3>{{post.date}}</h3>
<p>{{post.body}}</p>
{% endblock %}这个应该是单个页面上其余内容的模板。
如何将列表项目链接到正确的帖子?我在用马车开发当地的网站。
发布于 2016-02-08 13:11:01
我找到了解决问题的办法。
要只访问内容类型文章中的一个特定条目,您需要创建一个模板,该模板保存具有正确布局的内容。
这意味着您需要一个名为“content template.language”的文件,并且必须将该文件放在文件夹中(在我的例子中称为"post")来定义父文件:
/posts.liquid # Holds a list of all Posts
/post/content-type-template.liquid # Holds the layout for only one post同样,在内容类型模板的顶部,您需要定义内容类型和段塞:
---
title: Post Template
content_type: post
slug: content_type_template
---现在可以使用以下语法访问内容类型的字段:
{% extends parent %}
{% block main %}
<h2>{{post.title}}</h2>
<h3>{{post.date}}</h3>
<p>{{post.body}}</p>
{% endblock %}例如,如果内容类型名为"product",则需要将上面的所有名称都重命名为"post“,并将其命名为"product”。
最后,你可以到达一个条目与它的鼻涕虫。
{% extends parent %}
{% block main %}
{% for post in contents.posts%}
<a href="/post/{{ post._slug }}"><li>{{ post.date }} - {{ post.titel }} </li></a>
{% endfor %}
{% endblock %}以下是一些帮助我的链接:
http://www.tommyblue.it/2011/02/28/how-to-build-a-website-with-locomotive-cms-from-scratch/
http://doc.locomotivecms.com/references/api/objects/content-entry
https://stackoverflow.com/questions/35199148
复制相似问题