0

有一个相当基本的模板,可以输出主要文章,然后应该从同一频道输出其他三个,但是当使用以下代码时,“其他合作伙伴”区域没有任何输出,甚至没有“无帖子”,所以我真的没有确定出了什么问题。系统中有 5 篇以上的文章,所以肯定有结果要提取,有什么想法吗?

 {exp:channel:entries channel="partner" limit="1" url_title="{segment_3}"}

              <article>
                <h1>{title}</h1>
                {profile_logo:banner wrap="image"}
                {profile_body}
              </article>

{/exp:channel:entries}    

<h2>Other Partners</h2>
{exp:channel:entries channel="partner" related_categories_mode="yes" custom_fields="yes"}
   {if no_results}
     No posts
    {/if}
              <article>
                <a href="{url_title_path='community/partners'}">
                  {profile_logo:thumbnail wrap="image"}
                  <h3>{title}</h3>
                  <p>{profile_body}</p>
                </a>
              </article>
              {/if}
            {/exp:channel:entries}
4

2 回答 2

1

可能您在这里需要做的就是将dynamic="no"参数添加到您正在使用的第二个频道条目循环中related_categories_mode。您需要这样做,因为您在单个条目页面上,EE 将尝试使用url_titlepresent insegment_3专门为该条目加载通道数据。

所以你应该尝试:

<h2>Other Partners</h2>
{exp:channel:entries channel="partner" related_categories_mode="yes" custom_fields="yes" dynamic="no"}
    [...]
{/exp:channel:entries}

dynamic=该参数的官方文档在此处

还要确保您在浏览器中加载的条目的分类方式使得该频道中确实存在类似分类的其他条目。如果没有其他共享相同类别的条目,您正在使用的通道循环将不会加载任何条目related_categories_mode

此外,正如@Seibird 所提到的,在您的代码示例中,您if在结束标记之后看起来确实有一个额外的结束标记。article这很可能会造成干扰。

于 2012-11-21T15:47:23.827 回答
1

看起来你有一个 random {/if},不确定这是否会导致结果出现问题。您始终可以将当前类别传递给嵌入并像这样运行它:

{exp:channel:entries channel="partner" limit="1" url_title="{segment_3}"}

  <article>
    <h1>{title}</h1>
    {profile_logo:banner wrap="image"}
    {profile_body}
  </article>

  {embed="template_group/_related_partners" category="{categories backspace="1"}{category_id}|{/categories}"}
{/exp:channel:entries}

嵌入模板:

{exp:channel:entries channel="partner" category="{embed:category}" dynamic="no" url_title="not {segment_3}"}
   {if no_results}
   No posts
   {/if}
   <article>
    <a href="{url_title_path='community/partners'}">
      {profile_logo:thumbnail wrap="image"}
      <h3>{title}</h3>
      <p>{profile_body}</p>
    </a>
   </article>
{/exp:channel:entries}
于 2012-11-21T17:29:58.447 回答