« Homepage
ExpressionEngine Related Entries Module
29/06/09
Glen Swinfield
ExpressionEngine related entries can be prohibitive. This module allows you to use full weblog:entries tag functionality for related entries. No hack required. (PHP 5 only)
You may already be using the "Better Related Entries" extension previously available from my personal site. We have been using it internally here at Erskine for a while and overall it seems that the EE community have been using it in a number of interesting ways. The fact that it required a hack to the core to get it to work has always been an irritation to me. No more. This re-loaded module version requires no hack. Here's how it works.
Tech Stuff
The module works by extending the EE weblog class, it runs a query to get related entries and inserts a pipe-separated list of the IDs of those entries into the tag parameters. It's as if you had added the IDs yourself in the tag only it's dynamically getting them for you.
Because the Ed_related class extends the EE Weblog class the 'entries' method is available and unaffected so all of the usual parameters can be used.
Usage Example
Install the module in the usual way, remembering to add the language file to your languages folder. You can use the module tag in two ways:
- Inside an embed template inside a weblog:entries tag
- Inside a template using an url segment for the parent ID or url_title
Method one requires that you use an embed because it causes parsing issues inside a weblog:entries tag. Here's a classic "books belonging to authors" example:
Basic tag example:
{exp:ed_related:entries weblog="books" parent_url_title="{embed:parent_url_title}" paginate="bottom" limit="10" orderby="cf_book_order" sort="asc"}
<h2>{title}</h2>
<p>{cf_book_isbn}</p>
{/exp:ed_related:entries}
The parent entry can be given in either a parent_id or parent_url_title parameter. How you get these IDs or url_titles is up to you and probably dependent on your situation. For example it could be via an embed variable as in the example, but could also be from an url segment, this removes the need for the tag to always be inside a weblog:entries tag.
Available Parameters and Variables
All of the parameters and variables available in the weblog:entries tag can be used and operate in exactly the same way with the addition of the parent url_title or ID:
- parent_id="{embed:parent_id}"
- parent_url_title="{segment_3}"
Bear in mind...
This module basically runs another weblog:entries tag so there is extra overhead to consider. That said, we have been using it in some fairly complex situations on some high traffic sites and haven't found this to be prohibitive. Make sure you use the 'disable' parameter where you can.
Get the Module
- Ed_related module v1.0.1 (PHP5 ONLY)
Ed_related module v1.0.0 (PHP5 ONLY)
Change Log
- v1.0.1, 3rd August 2009. Fixed incorrect assignment of child_url_title
- v1.0.0, 29th June 2009. First release
Glen Swinfield published this at 14:00 on 29/06/09