0

I have recently upgraded a website to 2.9.0 from 2.5.x so I'm trying to take advantage of the new (to me) relationship capabilities, specifically the siblings tag. We have for a long time, had a relationship field (pro_related_program) set up in our programs channel where you can choose another program as a related program. This allowed us to create program series, with one overview program page (the mutual child of many parents) and child program pages with a link back to the overview page.

On those child program pages I'd like an "other programs in this series" link. Since it wasn't working for me, I build a bare bones template for testing:

<html><head><title>Test</title></head><body>
  <h1>relationship test</h1>
  {exp:channel:entries channel="programs" url_title="PFA" status="not nonexistant"}
    <h2>{title}</h2>

{siblings field="pro_related_program" status="not nonexistant"}{if siblings:no_results}No results a{/if}<p>{siblings:title}</p>{/siblings}

{pro_related_program}{pro_related_program:siblings field="pro_related_program" status="not nonexistant"}{if pro_related_program:siblings:no_results}No results b{/if}<p>{siblings:title}</p>{/pro_related_program:siblings}{/pro_related_program}

  {/exp:channel:entries}
</body></html>

the result is as follows:

<html><head><title>Test</title></head><body>
  <h1>relationship test</h1>

    <h2>Program title here</h2>

No results a

</body></html>

So what am I doing wrong?

  • Is it because both parents and children are both coming from the programs channel?
  • Is it, as I suspect it might be, because my relationship is backwards for how EE would like it to be for siblings? (The parent should be the overview?) Or to put it another way, do siblings only work on relationship entries where you can choose multiple children?
    • If that is the cause, is there a good way to fake the siblings tag for my situation?
    • If not, is there a way to use the channel entries tag to spit out a list of programs with a relationship field filled in? I can test all of these things, but if someone knows it would help.
0

OK, no answers were immediately forthcoming so I worked it out on my own. Two answer my questions at the end of the question:

  • It is not caused by both entries being from the same channel
  • It is because the relationship set up is backwards as far as the EE relationships field is concerned. It does appear that siblings only work on relationship fields where you have enabled multiple selections
    • There is a way to fake siblings in the case of multiple parents with a single child, I'll demonstrate it below. Good or not is for you to decide.
    • This question intentionally left unanswered. I don't know, I'm not ambitious enough to find out right now.

Fake it 'Til We Make it

Remember that my channel is programs and the relationship field we are working with is pro_related_program. We are trying to display other entries that are part of this program series, which means we are looking for other parents that share the same child entry. Here is the code that worked for me:

{pro_related_program channel="programs" field="pro_related_program" status="not open|closed|under_development"}
  <h2>Program Series</h2>
  <p>This session is part of a larger series.  For more information see <a href="{pro_related_program:title_permalink="programs/catalogue"}" title="TDLC: {pro_related_program:title}">{pro_related_program:title}</a></p>
  {pro_related_program:parents field="pro_related_program" status="not open|closed|under_development" orderby="entry_date" sort="asc"}
    {if pro_related_program:parents:total_results > 1}
      {if pro_related_program:parents:count ==1}<h3>Other Sessions in this Series</h3><ol>{/if}
      <li>
        {if pro_related_program:parents:url_title != segment_3}
          <a href="{pro_related_program:parents:title_permalink="/programs/catalogue"}">{pro_related_program:parents:title}</a>
        {if:else}
          {pro_related_program:parents:title}
        {/if}
      </li>
      {if pro_related_program:parents:count == pro_related_program:parents:total_results}</ol>{/if}
    {/if}
  {/pro_related_program:parents}
{/pro_related_program}

This page is loading the entry based on the url_title in segment_3. I decided to show the title of the current page as well, but toggle the link using {if pro_related_program:parents:url_title != segment_3} this could just as easily (slightly easier in fact) have been used to not show the current page title.

So how does this work? We use the relationship field tag {pro_related_program} to load the series overview page information and then use {pro_related_program:parents} to load all the session entries for the series. In retrospect this seems obvious, but it would have been very difficult to do with native tags before the relationships update. Namespacing opens up new realms of possibility.

I hope someday someone finds this useful.

| improve this answer | |
  • This shows the following error when I'm logged in as an admin and so have errors showing: A PHP Error was encountered Severity: Warning Message: array_merge() expects at least 1 parameter, 0 given Filename: relationship_parser/Tree_builder.php Line Number: 133 – UltraBob Oct 6 '14 at 1:07
  • When there are no parent entries. – UltraBob Oct 6 '14 at 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.