ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Relationships | List all related entries within the same channel

August 26, 2014 7:44am

Subscribe [3]
  • #1 / Aug 26, 2014 7:44am

    Tom_Watney

    18 posts

    Hello.

    I’m struggling to get my head around how to use relationships within EE. I have read through the documentation on this and can achieve simple relationships, but have spent several days attempting to solve this particular problem without success:

    On a single entry I wish to list all related entries (share the same relationship) within the same channel.

    event
    - title
    - body
    - venue (relationship to venue)

    venue
    - title

    {exp:channel:entries channel="event"}
    <h2>Event Name: {title}</h2>
    <p>{body}<br />
    {venue}<br />
    <h3>Other events at {venue}<h3></p>
    
    <p>XXXXXX</p>
    
    <p>{/exp:channel:entries}

    I’ve tried a combination {embed} and {parents}, but can’t seem to get what I want. What should go in replace of my XXXXXX?

  • #2 / Aug 26, 2014 10:05am

    Boyink!

    5011 posts

    You have to start thinking more specifically than just “related”. Related how? You can find children, parents and siblings of the current entry.

    In your case events are the parent since they “own” the relationship field to the child venue.

    I believe what you want are other parent entries (so other events with the same child venue).

     

     

  • #3 / Aug 26, 2014 10:57am

    Tom_Watney

    18 posts

    Okay, that is a fair point that I need to think more specifically and you have correctly identified what I’‘m trying to achieve (other parent entries - so other events with the same child venue).

    I though the way to achieve would be through {siblings}:

    {exp:channel:entries channel="event" dynamic="yes"}
    
    <h2>Event Name: {title}</h2>
    <p>        {body}<br />
            {venue}<br />
    <h3>Other events at {venue}<h3><br />
    {siblings channel="event" field="venue" show_expired="yes"}<br />
     {siblings:title}<br />
    {/siblings}<br />
    {/exp:channel:entries}

    But this outputs nothing. I know you’re trying to gently guide me, but any other pointers would be most welcome.

  • #4 / Aug 26, 2014 11:02am

    Boyink!

    5011 posts

    Since you are after other parents…I’d be looking at the parents tag:

    https://ellislab.com/expressionengine/user-guide/add-ons/channel/relationships.html#accessing-parents

  • #5 / Aug 26, 2014 11:43am

    Tom_Watney

    18 posts

    I had been trying that without success. I tried a few more permutations all without success.
    Am I close with this?:

    {exp:channel:entries channel="event" dynamic="yes"}
    <h2>Event Name: {title}</h2>
    <p>        {body}<br />
            {venue}<br />
    <h3>Other events at {venue}<h3><br />
    {/exp:channel:entries}       </p>
    
    <p>{exp:channel:entries channel="venue" show_expired="yes"}<br />
            {parents field="venue" show_expired="yes"}<br />
                    {parents:title}<br />
            {/parents}<br />
    {/exp:channel:entries}

    Sorry, I’m struggling with the concept of this and thank you for your patience.

  • #6 / Aug 27, 2014 6:33am

    Tom_Watney

    18 posts

    Okay, I’ve got there but I don’t think I’ve done it in the most efficient way.

    {exp:channel:entries channel="event" dynamic="yes"}
    <h2>Event Name: {title}</h2>
    <p>        {body}<br />
            {venue}<br />
    <h3>Other events at {venue}<h3></p>
    
    <p>{embed="embed/otherevents" the_id="{venue}{venue:entry_id}{/venue}"}</p>
    
    <p>{/exp:channel:entries}

    The embed:

    {exp:channel:entries channel="venue" dynamic="no" entry_id="{embed:the_id}"}
        {parents field="venue" channel="event" show_expired="yes" entry_id="not {embed:the_id}"}
            {parents:title}
    
        {/parents}
    {/exp:channel:entries}

    Thank you for your patience - but if you have a cleaner way please do let me know.

     

  • #7 / Aug 27, 2014 7:35am

    Boyink!

    5011 posts

    I think the logic-jump you need to make is the nesting of relationships.  Here’s a quick test I just did on my local install. The parents channel owns the relationship field and relates to entries in the kids channel. This loop goes through each parent, finds the kids, then using a nested relationship approach finds other parents for the kid.

    {exp:channel:entries channel="parents"}
    Parent: {title}
    
    Kids:
    
     {kids}
      {kids:title}
     
      Other Parents: 
    
      {kids:parents field="kids"}
       {kids:parents:title}
    
      {/kids:parents}
     {/kids}
    {/exp:channel:entries}

    In your case Events are the parents and venues are the kids.

  • #8 / Aug 28, 2014 5:43pm

    vibe9

    96 posts

    I tried Michael’s method as I have the same situation whereby Parents = News and Kids = Sports channels, but the problem is that the current Entry (e.g. a news article) is also included in the list of “Parents”.

    It seems that the {siblings} tag would be the way to go here, but using that also yields No Results for me.  Is this perhaps an EE 2.9 bug?

  • #9 / Aug 29, 2014 6:16am

    Boyink!

    5011 posts

    The current entry is a parent, so it’s entirely appropriate for it to be displayed using the Parents tag.

    Siblings would be other entries with the same parent as the current entry, not all the parents for the current entry. It’s like asking “where’s your brother” instead of “who’s your mother?”...😉

    If you get no results you probably have no other entries with the same parent. 

    If you don’t want the current entry displayed in the list of parents, just do a conditional to check the url title of the page against the url title of the related entry being returned, and don’t display if there is a match.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases