Glen Swinfield’s Website v2.0

“I work for Erskine Design in Nottingham. Which is nice. You've got choices, you can visit my homepage, take a look at the available downloads or view the blog archives. Please contact me whenever you like. Also, why not subscribe to the RSS feed.”

Better ExpressionEngine Related Entries

Getting the full functionality of the weblog entries tag for related and reverse related entries is easy, with a small extension and an even smaller hack.

Change Log
Date Version Detail
28/09/08 1.0.1 Class was named incorrectly - changed to Gms_related_entries

Download GMS Related Entries Extension (EE 1.6.x) V1.0.1

Basically, having information interrelated is fundamental to all but the simplest of site, and it has always seemed ridiculous that related entries provision in EE 1.6.x is a bit token. It doesn’t really offer you much flexibility or functionality, especially for ‘forward’ related entries. This extension (and hack) will allow you to use the usual weblog:entries tag, with a parent or child, url_title or id parameter to get related entries with all the gubbins you would usually get from the weblog:entries tag.

How it works

Basically we’ve got an extension that intercepts the template parsing process and inserts a pipe separated string of related entry_id’s into the tag parameters. So as far as EE is concerned you specified the id’s yourself in the template. Only you didn’t, the extension did it for you.

The problem

There is no hook in the template class that allows us to implement our extension where we need to, so wee need to add one. This is the only hack required, and it is very simple. Basically go to /core/template.php and around line 762 you will see some code like this:

$args  $FNS->assign_parameters($args);

Just after this we need to add a custom hook, so paste/type this code in:

// hack-hack-hack
if (isset($EXT->extensions['parse_template_assign_params']))
{
    $args 
$EXT->call_extension('parse_template_assign_params',$args);
}

IMPORTANT UPDATE:
Sorry, forgot to mention that you need to make the $EXT global in the function ‘parse_template()’ like this, props to Steve Sharpe at Gleam for the heads-up:

function parse_template()
    
{
        
global $FNS$EXT;

This hook is now available to the extension, so download and install it.

Usage

Basically you just use a normal weblog:entries tag, but you add one of four extra parameters:

Example

If I wanted to get all weblog_entries in my cars weblog that were related to a specific manufacturer - let’s imagine that {segment_3} is ‘Ford’…

{exp:weblog:entries weblog="cars" status="not Closed” parent_url_title="{segment_3}"}
{title} ~ {entry_date}
{/exp:weblog:entries}

Simple as that - ALL weblog:entries functionality is available.

Disclaimer

There is obviously going to be extra pressure on the database using this method - but I haven’t ran into any real issues with this and it is running on some large sites with less than accommodating servers. just mind how you go.

Name:

Email:

URL:

Remember my personal information

Notify me of follow-up comments?

ExpressionEngine

Other Posts