ExpressionEngine:循环遍历一个类别中的所有条目
我正在使用表达式引擎创建一个文档站点,使用博客模块。我有许多类别,其中包含子类别。类别和子类别包含条目。
我想为每个类别创建一个页面,输出该父类别中所有子条目和子类别的嵌套列表。顶部应该有一个面包屑,显示类别层次结构以及指向父类别的链接。
这是我的代码:
<!-- url /docs/category/category_id -->
<!-- Breadcrumb -->
<!-- This works on the page template, but on the category template it shows all the categories -->
{exp:weblog:entries weblog="docs" }
{categories}
<a href="{path='/category'}?category_id={category_id}&category_name={category_name}&category_description={category_description}">{category_name}</a> >
{/categories}
{title}
{/exp:weblog:entries}
<!-- List of Categories -->
<!-- This shows ALL of the categories. I want it to only show the parent category and its children -->
{exp:weblog:categories style="nested"}
<h1><a href="{path='weblog/category'}"{category_name}</a></h1>
{exp:weblog:entries category="{category_id}"}
<a href="{path='weblog/page'}">{title}</a>
{/exp:weblog:entries}
{/exp:weblog:categories}
I'm using expressionengine to create a documentation site, using the weblog module. I have a number of categories, which contain subcategories. Categories and subcategories contain entries.
I want to create a page for each category that outputs a nested list of all the child entries and subcategories within in that parent category. There should be a breadcrumb at the top that shows the category hierarchy with links to the parent categories.
Here is my code:
<!-- url /docs/category/category_id -->
<!-- Breadcrumb -->
<!-- This works on the page template, but on the category template it shows all the categories -->
{exp:weblog:entries weblog="docs" }
{categories}
<a href="{path='/category'}?category_id={category_id}&category_name={category_name}&category_description={category_description}">{category_name}</a> >
{/categories}
{title}
{/exp:weblog:entries}
<!-- List of Categories -->
<!-- This shows ALL of the categories. I want it to only show the parent category and its children -->
{exp:weblog:categories style="nested"}
<h1><a href="{path='weblog/category'}"{category_name}</a></h1>
{exp:weblog:entries category="{category_id}"}
<a href="{path='weblog/page'}">{title}</a>
{/exp:weblog:entries}
{/exp:weblog:categories}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我没有时间为您编写代码,但我确实有时间(希望)为您指出正确的方向。一位名叫 Laisvunas 的 ExpressionEngine 开发人员创建了多个 EE 附加组件,用于处理 EE 类别及其与其他类别和条目的关系。
我不会链接到所有这些内容,但他的 Devot:ee 上的开发人员页面列出了所有内容。他创建的最受欢迎的类别附加组件是子类别,它您想做的大部分事情。如果他的(和其他)附加组件无法帮助您解决问题,请随时告诉我们。
祝你好运!
I don't have time to write the code out for you, but I do have time to point you in (hopefully) the right direction. An ExpressionEngine developer by the name of Laisvunas has created several EE add-ons that deal with EE categories and their relationships to other categories and entries.
I won't link to them all, but his developer page on Devot:ee lists them all. The most popular category add-on that he's created is Child Categories, which does much of what you're looking to do. If his (and other) add-ons can't help you with your problem, feel free to let us know.
Best of luck!
---编辑---
我写了一个插件来解决这个问题:
https://github.com/adaambom/Category-Inheritance-Plugin-for-ExpressionEngine
-------------
这就是我最终的做法。
为了获取子类别列表,我传递了一个 URL 查询字符串参数category_id,然后运行这个:
它只深入一层,但这是我能做到的最好的。
此代码输出所有条目(必须对 url 进行硬编码):
作为旁注,我不建议使用表达式引擎来完成任何事情。对于博客,请使用 Wordpress。对于文档站点,请使用 wiki。我想我们将切换到铁路站点。
---EDIT---
I have since written a plugin that solves this problem:
https://github.com/adambom/Category-Inheritance-Plugin-for-ExpressionEngine
-------------
Here's how I ended up doing it.
To get a list of subcategories, I pass a URL querystring parameter category_id, and run this:
It only goes one level deep, but that's the best I could get it to do.
This code outputs all the entries (had to hard code the url):
As a side note, I would not recommend using expressionengine for much of anything. For a blog, use Wordpress. For a documentation site, use a wiki. We are going to be switching to a rails site, I think.
轻松处理输出类别(任意级别)的最佳插件是 GWcode CatMenu这是免费的。
Easily the best plugin for handling outputting categories (as many levels as you like) is GWcode CatMenu which is free.