The Metadata Plugin
Metadata Management for Manila
 
Site last updated
2/24/2006; 12:33:21 PM
 
Home

Why

Features

FAQ

Updates

Documentation

Download

Developers

Bugs

Feedback

Discuss

Planned
Features

 
 

Getting related information - the showRelated() Macro

Note that the showRelated macro has been superseded by the query() Macro; use the query() macro for faster response and more customization.

Robert Cassidy asked for a feature that would show related items. For example, you run a website that reviews jams and jellies. On your page reviewing Dry Creek Farms' Blackberry Jelly, you want to put a little box that says 'other reviews of blackberry-flavored jellies.'

Let me introduce a new macro, showrelated(metaname), which does this.

In the above example, suppose you have a meta type called keywords. One of the keywords is blackberry.

Just use showrelated("keywords"). Easy! The macro performs the following steps:

  1. Find out what values are associated with this meta type for this page ('blackberry' is associated with the 'keywords' meta type).
  2. For each value, check the index for other pages which also have this value.
  3. Return the list of pages as a linked list of titles.

Note that the field you specify must be indexed (otherwise there's nothing to look up).

Don't just think about keywords. Think about other things: flavors, product numbers, shirt sizes, names of plugins, r-rated stories, bug reports, user-contributed reviews...you name it. Just create a meta type for those items and use the new macro.

Isn't this fun?

The showrelated macro has many parameters, making it more useful and customizable. Now you can define how each related item is formatted. The default format is an HTML list:

showrelated (metaname,sortBy="score",header="<ul>",footer="</ul>",beforeItem="<li>",afterItem="</li>",
maxItems="50",includeSelf="",suppressSortby="",sortDirection="")

Notice the presence of the sortBy parameter. This can be any meta type, built-in or user-defined. For example, suppose you have divided your site into Sections by defining a Section meta type. Now you want to list all the pages in one section, sorted by date. Because postTime is a built-in meta type (i.e., it occurs in the message table), we could say

showrelated ("Section","postTime")

and we'd get a nice list of recently-updated pages with dates:

For context on this example, see Index Maintenance and notice that the sort order is different. In that example, we're sorting by showrelated's default, that is, score.

The maxItems parameter tells the computer how many results to return. That way if you want to list only the 3 most recent pages, you can.

If the includeSelf parameter is set to "includeSelf", the page that the macro is on will be included in the result list.

If the suppressSortby parameter is set to "suppressSortby", the parenthetical list (for example, the postTimes in the example above) will be suppressed.

If the sortDirection parameter is set to "reverseSort", the result list is sorted in reverse order.

Comments...


This page last updated Wednesday, December 27, 2000 at 3:21:00 PM. (18463)