ExpressionEngine: Sort channel listing by Related Entry

Can someone help me in sorting a channel listing by Related entry title please?

I have a channel ' teams ' which has a field team_region which depends on another channel ' regions '.

My code is as follows:

 {exp:channel:entries channel="teams" orderby="" sort="asc" limit="10"}
    <tr>
          <td>{title}</td>
          <td>{team_address}</td>
          <td>{related_entries id="team_region"}{title}{/related_entries}</td>
    </tr>
 {/exp:channel:entries}

I want to Sort the result by ' team_region >> title '. Is it possible to achieve this?

Thank You!


Why not take the opposite approach - start with the Regions channel, then use reverse related entries to list your teams. Add a query tag to grab the region's title from within the {reverse_related_entries} loop, and you should be good to go:

{exp:channel:entries channel="regions" orderby="title" sort="asc"}
{reverse_related_entries orderby="title" sort="asc" channel="teams"}
    <tr>
        <td>{title}</td>
        <td>{team_address}</td>
        <td>{exp:query sql="SELECT title as region_title FROM exp_channel_titles t LEFT JOIN exp_relationships r ON r.rel_child_id = t.entry_id WHERE r.rel_id = {team_region} LIMIT 1"}{region_title}{/exp:query}</td>
    </tr>
{/reverse_related_entries}
{/exp:channel:entries}

You might want to look at Playa from Pixel and Tonic. It's a powerful multi-relational tool with tons more options than the built-in relationships field.

You'll probably want to use something like

{exp:playa:parents channel="channelname" orderby="title"}

Link to docs →

链接地址: http://www.djcxy.com/p/66014.html

上一篇: 更改ExpressionEngine插件的分析顺序

下一篇: ExpressionEngine:按照相关条目排序频道列表