more fun with keywords and tags
Following up on Using keywords and tags to help visitors find related content, my keyword search template now includes a list of related tags.
This is based on Ishbadiddle's semantic web idea. I've modified his code to match with the way I do my entry keywords, and am using the MT-Grid plugin to create a tabular listing of the related tags (keywords). Here's the code:
<MTCollateCollect>
<MTSearchResults>
<MTLoop values="[MTEntryKeywords]" delimiter=" "><MTCollateRecord>
<MTCollateSetField name="subject_keyword">[MTLoopValue]</MTCollateSetField></MTCollateRecord></MTLoop>
</MTSearchResults>
</MTCollateCollect>
<p><b>Other tags related to <i><$MTSearchString$></i></b></p>
<table cellspacing="0" cellpadding="10">
<MTGrid num_columns="9" transpose="1">
<MTCollateList sort="subject_keyword:+:i:d">
<MTIfNotEqual a="[MTSearchString]" b="[MTCollateField name='subject_keyword']">
<MTGridCell>
<MTGridIfLeftColumn><tr></MTGridIfLeftColumn>
<td><a href="<$MTCGIPath$><$MTSearchScript$>?Template=keyword&search=<MTCollateField name="subject_keyword">&IncludeBlogs=1&SearchField=keywords" title="Index of posts relating to <MTCollateField name="subject_keyword">"><MTCollateField name="subject_keyword"></a></td>
<MTGridIfRightColumn></tr></MTGridIfRightColumn>
</MTGridCell>
</MTIfNotEqual>
</MTCollateList>
<MTGridTrailingCells>
<td> </td>
<MTGridIfRightColumn></tr></MTGridIfRightColumn>
</MTGridTrailingCells>
</MTGrid>
</table>
(you can see the full keyword search template here)
You will need the Collate and Compare plugins in addition to the ones mentioned in my previous entry.
What it does is create a listing of all tags for all entries that are in the search results. It removes any duplicates and then the tag that is the search term itself. So what you end up with is a list of tags that were used along with the search-term tag.
An example of how this works is my list of entries tagged with iraq. You'll see a list of all entries tagged with this word and then a list of related tags. Each of these tags was used in conjunction with "iraq" to tag an entry somewhere. Clicking on the name of the tag will bring up a list of all entries that use that tag.
Subscribe to this blog's feed
Comments
Glad you're finding this hack to be useful! I added your "external resources" idea to my tag pages.
One question for you -- the MTIfNotEqual used to work for me, as a way to elminate the currently referenced tag from the list of related tags. But now it doesn't work any more. Do you have any ideas on that?
Thanks!
Posted by: IshMEL | August 1, 2005 10:34 AM
Hi IshMEL,
Sorry for the delay in replying! The MTIfNotEqual is from a plugin, so you may want to contact the plugin developer for troubleshooting.
Hope this helps!
Posted by: Al-Munaqabah | August 5, 2005 11:55 PM