Skip to content

Instantly share code, notes, and snippets.

@masugadesign
Last active August 29, 2015 14:16
Show Gist options
  • Save masugadesign/f3cb1d6663265f123712 to your computer and use it in GitHub Desktop.
Save masugadesign/f3cb1d6663265f123712 to your computer and use it in GitHub Desktop.
ee-relationship-example
{!-- I should note that this entries loop IS inside a Switchee case
{prod_manufacturer} - the relationship field
====================================================================================== --}
{exp:channel:entries
channel="products"
url_title="{segment_2}"
}
<h2>{title}</h2>
{!-- related manufacturer (first instance of the relationship field) --}
{prod_manufacturer}
<p>Manufacturer: <a href="/manufacturers/{prod_manufacturer:url_title}">{prod_manufacturer:title}</a></p>
{/prod_manufacturer}
{prod_full_description}
{!-- Related News items of the related manufacturer (second instance of the relationship field) --}
{prod_manufacturer}
{prod_manufacturer:parents channel="news" orderby="date" sort="desc"}
{if prod_manufacturer:parents:count == '1'}
<h3>News</h3>
{/if}
<h4><a href="/news/{prod_manufacturer:parents:url_title}">{prod_manufacturer:parents:title}</a></h4>
<span>{prod_manufacturer:parents:entry_date format="%M %j, %Y"}</span>
{prod_manufacturer:parents:news_overview}
{if prod_manufacturer:parents:count == prod_manufacturer:parents:total_results}
<br>
{/if}
{/prod_manufacturer:parents}
{/prod_manufacturer}
{/exp:channel:entries}
{!--
Because having duplicate {prod_manufacturer} tag pairs in the entries loop would make the second instance not parse,
I instead keep a single loop but Stash part of it and move it back up where it needs to go (mfg_link)
Working example:
--}
{exp:channel:entries
channel="products"
url_title="{segment_2}"
}
<h2>{title}</h2>
{!-- related manufacturer --}
{exp:stash:get name="mfg_link" process="end"}
{prod_full_description}
{!-- Related News items of the related manufacturer - tricky! --}
{prod_manufacturer}
{exp:stash:set name="mfg_link"}
<p>Manufacturer: <a href="/manufacturers/{prod_manufacturer:url_title}">{prod_manufacturer:title}</a></p>
{/exp:stash:set}
{prod_manufacturer:parents channel="news" orderby="date" sort="desc"}
{if prod_manufacturer:parents:count == '1'}
<h3>News</h3>
{/if}
<h4><a href="/news/{prod_manufacturer:parents:url_title}">{prod_manufacturer:parents:title}</a></h4>
<span>{prod_manufacturer:parents:entry_date format="%M %j, %Y"}</span>
{prod_manufacturer:parents:news_overview}
{if prod_manufacturer:parents:count == prod_manufacturer:parents:total_results}
<br>
{/if}
{/prod_manufacturer:parents}
{/prod_manufacturer}
{/exp:channel:entries}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment