ExpressionEngine:循环遍历一个类别中的所有条目

发布于 2024-10-24 21:40:14 字数 1078 浏览 1 评论 0原文

我正在使用表达式引擎创建一个文档站点,使用博客模块。我有许多类别,其中包含子类别。类别和子类别包含条目。

我想为每个类别创建一个页面,输出该父类别中所有子条目和子类别的嵌套列表。顶部应该有一个面包屑,显示类别层次结构以及指向父类别的链接。

这是我的代码:

<!-- 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

恋你朝朝暮暮 2024-10-31 21:40:14

我没有时间为您编写代码,但我确实有时间(希望)为您指出正确的方向。一位名叫 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!

打小就很酷 2024-10-31 21:40:14

---编辑---

我写了一个插件来解决这个问题:
https://github.com/adaambom/Category-Inheritance-Plugin-for-ExpressionEngine

-------------

这就是我最终的做法。

为了获取子类别列表,我传递了一个 URL 查询字符串参数category_id,然后运行这个:

<ul>
    {exp:query sql="SELECT cat_id as child_category_id, cat_name AS child_category_name FROM exp_categories WHERE parent_id = '<?php echo addslashes($_GET['category_id']) ?>' ORDER BY category_name ASC"}
        <li><a href="{path=/category/}?category_id={child_category_id}">{child_category_name}</a></li>
    {/exp:query}
</ul>

它只深入一层,但这是我能做到的最好的。

此代码输出所有条目(必须对 url 进行硬编码):

{exp:weblog:entries category="<?php echo $_GET['category_id'] ?>"}
    <p><a href="/simulate/docs2/index.php/page/{entry_id}">{title}</a></p>
{/exp:weblog:entries}

作为旁注,我不建议使用表达式引擎来完成任何事情。对于博客,请使用 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:

<ul>
    {exp:query sql="SELECT cat_id as child_category_id, cat_name AS child_category_name FROM exp_categories WHERE parent_id = '<?php echo addslashes($_GET['category_id']) ?>' ORDER BY category_name ASC"}
        <li><a href="{path=/category/}?category_id={child_category_id}">{child_category_name}</a></li>
    {/exp:query}
</ul>

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):

{exp:weblog:entries category="<?php echo $_GET['category_id'] ?>"}
    <p><a href="/simulate/docs2/index.php/page/{entry_id}">{title}</a></p>
{/exp:weblog:entries}

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.

谁把谁当真 2024-10-31 21:40:14

轻松处理输出类别(任意级别)的最佳插件是 GWcode CatMenu这是免费的。

Easily the best plugin for handling outputting categories (as many levels as you like) is GWcode CatMenu which is free.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文