“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.”
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.
| 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.
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.
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.
Basically you just use a normal weblog:entries tag, but you add one of four extra parameters:
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.
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.
Steven Hambleton ~ Thursday, Sep 18th 2008 @ 03:22:32
Great extension Glen!
I have been wrangling with related entries for a while now and there is so much scope for improvement. Hopefully these will be addressed in EE 2.0.
PS. Did you post this in the forums? I think you should. EllisLab needs to be aware of just how much improvement is needed in this area!
Stanislav Majerski ~ Monday, Sep 22nd 2008 @ 20:32:48
Seems like the links is download broken. Could you check? I am getting “Internal Server Error”.
Thanks
Glen ~ Tuesday, Sep 23rd 2008 @ 08:12:36
@Stanislav - it seems to be working now. I’m not sure what the problem was, it was something to do with the filename I think. I’ll look into it later when I have more time.
Thanks for letting me know.
Stanislav Majerski ~ Tuesday, Sep 23rd 2008 @ 10:05:41
yes it works. Thank you very much will give it a spin once i grab some little free time. Thanks again
Phil ~ Tuesday, Sep 23rd 2008 @ 12:37:26
Your extension has been very useful and works well with Brandon Kelly’s Playa extension, thanks Glen
Steve P. Sharpe ~ Monday, Sep 29th 2008 @ 09:52:10
Hi Glen,
For some reason this is not showing up in the extensions panel in EE 1.6.4, any ideas?
Cheers
Steve
P.S. Looks like a life saver extension!
Steve P. Sharpe ~ Monday, Sep 29th 2008 @ 10:09:22
Ok sorted it: The class was called “Esk_related_entries”, it should have been called “Gms_related_entries”. I renamed it and EE then found it in the extension manager.
Glen ~ Monday, Sep 29th 2008 @ 10:42:02
Thanks Steve, I’ll get that corrected and re-upload it as v1.0.1 or something. Glad it’s useful.
Let know know if you need/add any helpful additions.
Glen ~ Monday, Sep 29th 2008 @ 13:28:47
Folks you need to make the $EXT global in the parse_template() function in the core.template file.
Thanks for pointing that out Steve.
I have added these instructions to the post.
Steve P. Sharpe ~ Thursday, Oct 16th 2008 @ 13:22:23
Hi Glen,
Any ideas how to get this working with the Playa extension? It pulls in the entries fine, but not in the right order. I’m new to playa, so sorry if it’s an obvious question.
Cheers
Steve
Glen Swinfield ~ Thursday, Oct 16th 2008 @ 13:37:39
Hi Steve,
Basically (sorry if I’m telling you stuff you already know) all that is happening is that a string of pipe separated entry id’s are being inserted in to the weblog:entries tag. E.g. 12|3|5|7|10 - it is then the orderby="” and sort="” in the weblog:entries tag that sorts them.
If this isn’t working then I’m not sure. Are you using statuses? Player is a bit odd if you relate entries that have statuses that aren’t ‘open’.
You’ve got my email so send me some code or a link and I’ll have a look.
cheers.
Zander Martineau ~ Friday, Oct 31st 2008 @ 18:49:15
I’ve just stumbled upon this plugin and it looks to be able to do exactly what I want, but I have just upgraded to EE 1.6.5 and, unless I’m being an idiot, I can’t seem to find the$args = $FNS->assign_parameters($args); code with which to paste the other code after.
Know what I mean?
Thanks
Glen Swinfield ~ Saturday, Nov 1st 2008 @ 10:41:09
@Zander - in 1.6.5 its in system/core/core.template.php around line 774 - it looks like this:
// Assign the class name/method name and any parameters
$class = $this->assign_class(substr($tag, strlen(’exp’) + 1));
$args = $FNS->assign_parameters($args);
// put hack code here.
Zander Martineau ~ Saturday, Nov 1st 2008 @ 11:11:29
Thanks mate, I’ll try it out
jarin ~ Saturday, Nov 1st 2008 @ 18:52:34
hey thanks for yr work on this
ive installed playa and this extension plus edited the core template as per above.
it seems to be working fine on the backend, in that i can choose multiple entries via playa when editing an entry.
ive put in the playa example code in my template like so:
{related_entries id="related"}
<h4>{title}</h4>
{body}
{/related_entries}
but i get the below on the article page:
{REL[7][related]SRohzkV5REL}{REL[8][related]SRohzkV5REL}
i presume i’m meant to be using something that looks like the example code you’ve provided on this page but i’m not sure how this works with playa? would it be possible for someone to provide an example of something like this:
{exp:weblog:entries weblog="cars" status="not Closed” parent_url_title="{segment_3}"}
{title} ~ {entry_date}
{/exp:weblog:entries}
but set up in a way that will work with playa?
or am i being completely dense?
thanks!
Leevi Graham ~ Friday, Nov 14th 2008 @ 00:04:54
Hey Glen,
Have you added a feature request for this extension hook?
Derek is usually pretty good with feature requests if you can present a strong case.
Thanks for the extension, trying it out now!
Leevi Graham ~ Friday, Nov 14th 2008 @ 00:10:47
Oh I just had a thought. How does this work with pages that don’t have a specific url_title or entry_id in the url?
Maybe you could add:
parent_id="current_page" or something like that?
jarin ~ Monday, Dec 1st 2008 @ 22:05:49
hi..is my question invisible? if anyone could help it’d be greatly appreciated! i think many novice EE developers would benefit from a clearer explanation of how this great mod is meant to work with playa!
thanks in advance
Glen ~ Monday, Dec 1st 2008 @ 22:40:03
Jarin,
The extension has nothing to do with Playa really. Playa provides you with (a very good) way of entering multiple relationships in the exp_relationships DB table, but this extension does nothing to or with playa, it just happens that playa makes this extension more useful because it helps you to create multiple relationships.
What this extension does, instead of using the native EE {related_entries} stuff, it queries the exp_relationships table directly and inserts the Id’s of related weblog entries into the entry_id="” tag parameter (hence the hack).
All it uses is the rel_parent_id and rel_child_id values in the relationships table, the rest is irrelevant.
I don’t know why your related_entries tag is not working, I haven’t seen that behaviour before.
I hope this helps.
jarin ~ Tuesday, Dec 2nd 2008 @ 00:15:56
hey glen thanks much for getting back to me. i’m pretty new to expression engine and still not really clear on how to get this working.
when i use the related entries tag suggested by the playa developer, all i’m getting is the gobbledygook i mentioned before.
it’s totally unclear to me how to use the example weblog:entries tag you show above. when i use something similar, all it shows me is the title and date of the article i’m viewing, not the 3 related stories i’ve chosen in admin via playa for that article.
i’d be more than happy to pay someone to fix this for me!
Gregorious ~ Tuesday, Dec 2nd 2008 @ 09:52:48
@jarin sounds like the problem is your use of playa.
It’s totally unclear to me how to use the example weblog:entries tag you show above. when i use something similar, all it shows me is the title and date of the article i’m viewing, not the 3 related stories i’ve chosen in admin via playa for that article.
Sounds like you need to use the dynamic="off" parameter in your weblog entry tags
jarin ~ Tuesday, Dec 2nd 2008 @ 10:09:06
hi thanks for getting back to me gregorious
if i put dynamic="off" in the main entry tag (not the one involving the related entries) i get an error at core.functions.php about allowed memory being all used up.
if i put dynamic-"off" in the weblog:entries tag as proposed above (the one that should be showing me the related entries but is instead showing me the title and entry date of the story i’m viewing), it makes no difference and i still just see the title and entry date of the story i’m viewing.
anyone want to make a few pounds to fix this? seriously. this is the final thing that is keeping me from completing this project.
Glen Swinfield ~ Tuesday, Dec 2nd 2008 @ 10:45:37
Jarin,
The point of this extension is to replace the ‘related_entries’ tag with a normal weblog:entries tag. This is achieved by adding either parent_id, child_id, parent_url_title or child_url_title to the exp:weblog:entries tag - this parameter should contain the id o or url title of the related entry.
If you need to put this inside another weblog entries tag then you will need to use an embed - alternatively you could use an url segment {segment_3} as the parent or child url title.
Also, if php is running out of memory you need to either adjust your php.ini settings or perhaps add ini_set(’memory_limit’,’’16M’); to your index.php file - or somewhere else convenient.