【问题标题】:ExpressionEngine: Help w/ Ordering Reverse Related EntriesExpressionEngine:帮助 w/ 排序反向相关条目
【发布时间】:2012-10-16 05:54:13
【问题描述】:

我在排序一些反向相关条目时遇到了一些问题。 EE 有一些限制,我正在寻找一个快速的解决方案。我们将不胜感激您能提供的任何帮助。

我有两个渠道:注册和学生。学生有一个关系字段,将每个条目链接到注册通道中的条目。 (我需要继续使用 EE 关系字段。)

学生频道有两个类别组分配给它:成绩(第 1 组)和乐器(第 2 组)。类别 ID #1-6 属于等级类别。

以下代码实现了我需要它做的一半:

{exp:channel:entries channel="registrations" entry_id="{segment_4}" dynamic="no"}
<table>
{reverse_related_entries channel="students"}
{categories show="1|2"}
 <tr>
  <td><?php print $count; ?>.</td>
  <td>{title}</td>
  {embed="_includes/student_print" student_id="{entry_id}"}
 </tr>
{/categories}
{/reverse_related_entries}
</table>
<table>
{reverse_related_entries channel="students"}
{categories show="3|4"}
 <tr>
  <td><?php print $count; ?>.</td>
  <td>{title}</td>
  {embed="_includes/student_print" student_id="{entry_id}"}
 </tr>
{/categories}
{/reverse_related_entries}
</table>
<table>
{reverse_related_entries channel="students"}
{categories show="5|6"}
 <tr>
  <td><?php print $count; ?>.</td>
  <td>{title}</td>
  {embed="_includes/student_print" student_id="{entry_id}"}
 </tr>
{/categories}
{/reverse_related_entries}
</table>
{/exp:channel:entries}

这是 student_print 嵌入:

{exp:channel:entries channel="students" entry_id="{embed:student_id}" dynamic="no"}
<td><font size="2">{categories show_group="2"}{category_name}{/categories}</font></td>
<td><font size="2">{categories show_group="1"}{category_name}{/categories}</font></td>
{/exp:channel:entries}

现在 - 我需要它做的是按仪器类别组(组 #2)中类别的自定义顺序对反向相关条目进行排序。我只是不知道如何去做我目前正在做的事情(显示三个表——每个表都显示来自组#1 中特定类别的条目)并将它们按组#2 中的类别的自定义顺序排列。

再次 - 组 #2 中的类别按自定义顺序排列,我需要按该自定义顺序显示相关条目。这很重要。

有什么想法吗?这可以通过自定义查询来完成吗?我真的很感激一个代码示例——如果可能的话。这是在扩展我的 EE 和 SQL 能力。

非常感谢您的宝贵时间。

【问题讨论】:

    标签: expressionengine


    【解决方案1】:

    我真的不再使用原生关系,这对我来说太麻烦了。所以普拉亚会更好。但是,我发现了这个错误,可能与您的问题有关: http://expressionengine.com/bug_tracker/bug/16373

    【讨论】:

      【解决方案2】:

      老实说,我的第一印象是这是错误的结构方式。太复杂了。但这总是很容易说来自外部对吧? :)

      其次,我不确定您需要此注册频道的目的是什么,因为您似乎没有使用其中的任何数据(除非您为了清晰起见删除了一些代码)?

      但无论如何,这里有一些未经测试的代码。要点是您只能使用channel:categories 标签按类别排序,然后将{category_id} 传递给新的channel:entries 标签。如果我们将所有 entry_id 的列表传递给其中的每个标签,它应该过滤掉所有不属于您传递的特定 {category_id} 的内容。

      {exp:channel:entries channel="registrations" entry_id="{segment_4}" dynamic="no"}
          {embed="_includes/student_print" entry_ids="{reverse_related_entries channel="students" backspace="1"}{entry_id}|{/reverse_related_entries}"}
      {/exp:channel:entries}
      

      然后你的嵌入看起来像这样:

      {exp:channel:categories channel="students" style="linear" show="1|2"}
      {if count == "1"}<table>{/if}
          {exp:channel:entries channel="students" entry_id="{embed:entry_ids}" category="{category_id}" dynamic="no"}
          <tr>
              <td><?php print $count; ?>.</td>
              <td>{title}</td>
              <td><font size="2">{categories show_group="2"}{category_name}{/categories}</font></td>
              <td><font size="2">{categories show_group="1"}{category_name}{/categories}</font></td>      
          </tr>
          {/exp:channel:entries}
      {if count == total_results}</table>{/if}
      {/exp:channel:categories}
      
      {exp:channel:categories channel="students" style="linear" show="3|4"}
      {if count == "1"}<table>{/if}
          {exp:channel:entries channel="students" entry_id="{embed:entry_ids}" category="{category_id}" dynamic="no"}
          <tr>
              <td><?php print $count; ?>.</td>
              <td>{title}</td>
              <td><font size="2">{categories show_group="2"}{category_name}{/categories}</font></td>
              <td><font size="2">{categories show_group="1"}{category_name}{/categories}</font></td>      
          </tr>
          {/exp:channel:entries}
      {if count == total_results}</table>{/if}
      {/exp:channel:categories}
      
      {exp:channel:categories channel="students" style="linear" show="5|6"}
      {if count == "1"}<table>{/if}
          {exp:channel:entries channel="students" entry_id="{embed:entry_ids}" category="{category_id}" dynamic="no"}
          <tr>
              <td><?php print $count; ?>.</td>
              <td>{title}</td>
              <td><font size="2">{categories show_group="2"}{category_name}{/categories}</font></td>
              <td><font size="2">{categories show_group="1"}{category_name}{/categories}</font></td>      
          </tr>
          {/exp:channel:entries}
      {if count == total_results}</table>{/if}
      {/exp:channel:categories}
      

      我不知道你在其中的这个 $count PHP 变量是什么,但它可能需要修改,因为它现在在嵌入中。

      让我知道这是否有任何结果?

      【讨论】:

      • 这并没有太大变化。问题仍然是试图获得按类别组#2 排序的三个分组中的每一个中的结果。现在:{categories show_group="2"}{category_name}{/categories} {categories show_group="1"}{category_name}{/categories} 两者都输出组 #1 的 category_name。还有其他想法吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 2011-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多