Related Entries plugin for Mango Blog
This plugin has been a long time in the making. It's something I knew from the outset that I would want in Mango, but after getting my feet wet by writing a few other small plugins, I knew I could do it. I made it as simple as I could, but there are still a couple of things you will need to know; one of which is that you might need to modify your theme to broadcast a new event in a couple of places. This new event is going to be a part of future versions of Mango, so there isn't any worry about future-compatibility and worries when upgrading.
First of all, though you need a small update to the core of Mango. Even if you've got the latest version of Mango (1.1)! Laura posted a comment on the plugin ideas page with a link to the update zip file, and an explanation that it included a new plugin (home page chooser), some core modifications that were needed to support that plugin, and most importantly, some bug fixes — one of which is necessary for back-linking of related entries to work correctly. So before you do anything else, make sure you grab and install that update!
Once you've got the Mango update installed, go ahead and download my Related Entries plugin.
Now about that event. It's really simple to add. Open up your theme's index.cfm and post.cfm files (and archives, and other places you may want to show related entries…). The code to broadcast the event is really simple:
<mango:Event name="beforePostContentEnd" />
Simple, right? And where do you put it? Anywhere, really… within reason. It uses contextual information to look up related entries data for the current post, so you must broadcast it inside of a <post> (custom tag) block. So for example, here's the relevant information from my theme's index.cfm template:
<mango:Posts count="5">
<mango:Post>
...
<mango:Event name="beforePostContentEnd" />
<p class="date">Posted in ...</p>
...
</mango:Post>
</mango:Posts>
That's almost it! After you install the plugin, and add the event broadcast to your theme, there's just 2 more things.
First, relate a couple of entries. Edit a post, and look at the bottom of the form.

This new section should be displayed at or toward the bottom of the form. As it explains, you select a category from the left column to see its entries from the selected categories (use control to select multiple). Then click on any entries from the center column that you want to relate to the current entry; they will be displayed in the right column. (This is all done with jQuery ajax!) To remove an entry from the right column, double click it. When you submit the form, the posts in the right column will be marked as related to the current entry; and in addition to that, the current entry will be related to those posts.
When you submit the form, if you get an error that looks like this, then you didn't install the update!:

If you don't get the above error, then your data should be good to go. Now, you just need to style it.
When you've got related entries data, the event you're broadcasting is going to be replaced with some code along this line:
<div class="related">
<h2 id="RelatedEntries">Related Entries:</h2>
<ul>
<li><a href="http://server/post/your-post">Post Title</a></li>
<li><a href="http://server/post/your-post">Post Title</a></li>
<li><a href="http://server/post/your-post">Post Title</a></li>
</ul>
</div>
So, you can define some css rules for .related, #RelatedEntries (or .related h2), and .related ul, .related ul li, .related ul li a.
That's it. Enjoy!
One note for the future: The update I talk about above should be included in Mango 1.2, so if you've got 1.2 (or later) installed, don't worry about the update.
In case you missed the link before, you can Download my Related Entries Mango Blog Plugin right here.
Posted in AJAX | ColdFusion | JavaScript | Mango | My projects | 23 Responses
I am modifying mine a bit though. I am removing id="RelatedEntries" from the h2. Since the h2 is inside the div "related" you only need to refer to it in your css as
.related h2 and your golden. :)
Also, if you have more than one on your homepage where you show more than one item, having multiple ID's is not exactly valid.
Whoot! Finally Related Articles! Thanks again Adam!
Good job! I am glad you got it working ;)
This plugin was something that I really wanted for myself, and now I have it!
BTW, regarding the new event, it will be available in the updates for the themes. The only thing is that I've only been adding it to the post pages and not in the home or archives. I guess it depends on the application, but if I wanted to have ads there, for instance, I wouldn't want to have them at the footer of every post.
One other thing, I would change the header to something of less importance, like h4 or h5. h2 is usually used for entry titles and other more important elements.
I added the event to my archives and index pages because I wanted it to be displayed there. Certainly, if someone doesn't want related entries displayed on their home page and only in archives/individual post, they can leave index alone.
Perhaps, though, this is a good case for separate events on each?
beforeInedxPostContentEnd, beforeIndividualPostContentEnd, beforeArchivesPostContentEnd
Just a thought.
Makes me feel guilty though, that for some reason I've not posted to my blog or made any Mango plugins for over 6 months...
Definitely time to rectify that, and build my own skin too!
Keep up the good work...
Thanks for your work.
But I'm facing the same issue as Jonese and Tiffany.
List of categories shows up in the admin when adding/editing a post. But clicking on a category does not do anything. There are no Javascript errors either.
Indy
1. Line 264 in plugin.cfc creates a variable called ajaxPath. It is evaluate to an incorrect path on my install. Therefore the ajax call being made to retrieve the categories doesn't work. If you use an HTTP sniffer you can see the 404.
So I changed the variable ajaxPath to point to the correct path. Which in my case is: /blog/components/plugins/user/RelatedEntries/assets/RelatedEntries.cfc
So that takes care of the fact that a correct Ajax call is being made.
2. The second issues is that I'm using CF 702 (yes, yes, I know I should upgrade, but my hosting company is a bit slow).
And using CF702 seems to give the issue that function getEntriesByCatIdList() in RelatedEntries.cfc returns a WDDX packet instead of a JSON packet. I have a feeling that returnFormat was not supported in CF702.
So I'll have to look at a way to return JSON string from a CF function in CF702. I remember there was some issue with this and in the past I had to revert back to using a CFM file to generate the JSON packet.
Will keep you posted.
what version are you running of mango and of Related Entries?
The .2 beta that you sent works beautifully on CF702.
http://mangobloghosting.com
I think I might be experiencing the same problem as Indy and the others. Has the fix been made publicly available? If not, could you possibly email it to me as well?
Can you help?
Can you at least tell me which table these are stored in so I can remove the offending current entries?
<cfset arguments.event.setOutputData(local.relEntryLinkList)/>
This should be <cfset arguments.event.setOutputData(arguments.event.getOutputData() & local.relEntryLinkList)/>
because otherwise, all other event-output is not displayed anymore! (like my own viewcount plugin...)
Thanks for the plugin though :-)