Related Entries 1.1 Entries
The Related_Entries:Entries function provides you with a more flexible and powerful feature set than the Related Entries variable pairs. The variable pairs are available for a simple display of related entries. However, the Related_Entries:Entries loop contains most of the parameters and variables available in the Weblog:Entries loop so it allows for more flexible usage.
Parameters
Most of the parameters available in the Weblog:Entries loop are available here. Additionally, these exist as well:
main_only=
main_only="yes"
Specifying the 'main_only' parameter will show only the main related entry. Note: can only be used for regular related entries - not available for reverse related entries.
direction=
direction="reverse"
Specifying the 'direction' parameter allows you to display 'forward' (regular), 'reverse', or 'both' entries. Reverse related entries will show all entries that are related to the entry being shown. Reverse related entries are entries that have assigned a specified entry as a related entry. For example, if Entry B and Entry C added Entry A as a related entry, Entry B and Entry C would be Entry A's reverse related entries. Specifying 'both' will show both regular and reverse related entries. If this parameter is unspecified, the default value is 'forward'.
Variables
Most of the variables available in the Weblog:Entries loop are available here.
Variable Pairs
Most of the variable pairs available in the Weblog:Entries loop are available here.
Conditionals
Most of the conditionals available in the Weblog:Entries loop are available here. Additionally, these exist as well:
if related_primary
{if related_primary}{/if}
The 'if related_primary' conditional is available to determine whether or not an entry is the primary related entry. For example, using an {if related_primary}Main Related Entry{/if} statement, you can specify a different or additional CSS class, image, text for that entry. Avalable only with "forward" or "reverse". Otherwise, only works with "forward" entries when using "both".
Examples
The following is a basic example of how you would use the Related_Entries:Entries loop within a single entry page:
{exp:weblog:entries}
<h1>{title}</h1>
<p>{body}</p>
<hr />
{/exp:weblog:entries}
<h2>Related Entries</h2>
{exp:related_entries:entries}
<div class="related">
<h3>{title}</h3>
<p>{body}</p>
<p>{another_custom_field}</p>
</div>
{/exp:related_entries:entries}
The following is a basic example of how you would display the "main" related entry using the Related_Entries:Entries loop within a single entry page:
{exp:weblog:entries}
<h1>{title}</h1>
<p>{body}</p>
<hr />
{/exp:weblog:entries}
<h2>Related Entries</h2>
{exp:related_entries:entries main_only="yes"}
<div class="related">
<h3>{title}</h3>
<p>{body}</p>
<p>{another_custom_field}</p>
</div>
{/exp:related_entries:entries}
The following is a basic example of how you would display Reverse related entries using the Related_Entries:Entries loop within a single entry page:
{exp:weblog:entries}
<h1>{title}</h1>
<p>{body}</p>
<hr />
{/exp:weblog:entries}
<h2>Related Entries</h2>
{exp:related_entries:entries direction="reverse"}
<div class="related">
<h3>{title}</h3>
<p>{body}</p>
<p>{another_custom_field}</p>
</div>
{/exp:related_entries:entries}
The following is a more advanced example of how you can use the Related_Entries:Entries loop within a single entry page:
{exp:weblog:entries}
<h1>{title}</h1>
<p>{body}</p>
<hr />
{/exp:weblog:entries}
<h2>Related Entries</h2>
{exp:related_entries:entries weblog="weblog_2" status="open|closed|sandwich" orderby="entry_date" sort="asc" limit="5"}
<div class="related{if related_primary}_main{/if}">
<h3>{if related_primary}Main: {/if}{title}</h3>
<p>{body}</p>
<p>{custom_field}</p>
{if related_primary}<p>{another_custom_field}</p>{/if}
</div>
{/exp:related_entries:entries}
The following is an example of how you can use the Related_Entries:Entries loop within a multi-entry view page using an embed method:
Main Template:
{exp:weblog:entries}
<h1>{title}</h1>
<p>{summary}</p>
<h2>Related Entries:</h2>
{embed="path_to/embed" entry_id="{entry_id}"}
<hr />
{/exp:weblog:entries}
Embedded Template:
<ul>
{exp:related_entries:entries direction="both" entry_id="{embed:entry_id}" limit="15"}
<li>{title}</li>
{if no_results}
<li>No soup for you!!</li>
{/if}
{/exp:related_entries:entries}
</ul>