5

所以,我已经搜索过,发现了一些可以让我得到我想要的帖子,但它仍然不太有效。这篇文章似乎最接近我想要实现的目标,我以此为基础构建了我的代码:http ://expressionengine.com/forums/viewthread/168142/

解释; 我有一系列条目,每个条目只分配给一个类别。我想列出这些类别,并在每个类别下,列出具有其中一个自定义字段的条目。像这样:

  • 第一类

    • 项目 1
    • 第 2 项
  • 第 2 类

    • 项目 1
    • 第 2 项

所以,这是我现在的代码,它列出了类别,但根本没有吐出任何条目:

{exp:channel:categories channel="faq-question" style="linear"}
    <section class="faq-category-container closed">
        <h1 class="faq-category-header"><a href="#">{category_name}</a></h1>
        <dl>
    {exp:query sql="

        SELECT title, url_title AS urlt, cat_id

        FROM exp_channel_titles

        NATURAL JOIN exp_category_posts

        WHERE channel_id = '7' AND cat_id = '{category_id}'

        ORDER BY title ASC"
    }
        {embed="jazz-camp/faq-cat-list" faqlink="{urlt}"}
    {/exp:query}
        </dl>
    </section><!-- end .faq-category -->
{/exp:channel:categories}

以及它引用的嵌入式模板:

{exp:channel:entries channel="faq-question" url_title="{embed:faqlink}"}<!-- entry -->
    <dt>{title}</dt>
    <dd>
        {faq_content}
    </dd>
{/exp:channel:entries}

非常感激任何的帮助!

4

3 回答 3

14

This may be a very basic example of what you're after:

{exp:channel:categories style="linear"}
  <h1>{category_name}:</h1> 
  {exp:channel:entries category="{category_id}" dynamic="no"}
    <p>{my_custom_field}</p>
  {/exp:channel:entries}
{/exp:channel:categories}
于 2011-01-26T21:14:34.923 回答
5

所以,这就是我最后得到的结果(感谢 EE 委员会的一些帮助):

{exp:channel:categories channel="faq-camp" style="linear" show_empty="no"}
    <section class="faq-category-container closed">
        <h1 class="faq-category-header"><a href="#">{category_name}</a></h1>
        <div class="faq-questions-container">
            <dl>
    {embed="jazz-camp/faq-cat-list" faqlink="{category_id}" faqparent="faq-camp"}
            </dl>
        </div><!-- end .faq-questions-container -->
    </section><!-- end .faq-category -->
{/exp:channel:categories}

至于嵌入,它看起来像这样:

{exp:channel:entries channel="{embed:faqparent}" category="{embed:faqlink}" dynamic="no"}<!-- entries -->
    <dt>{title}</dt>
    <dd>
        {faq_answer}
    </dd>
{/exp:channel:entries}

嵌入的原因与如何获取正确的频道条目有关;仅仅{exp:channel:entries}在页面中添加内联内容并不太奏效。

于 2011-01-28T15:55:32.067 回答
1

分类存档标签可能对您有所帮助:

http://ellislab.com/expressionengine/user-guide/modules/channel/category_archive.html

于 2014-02-11T01:27:22.163 回答