Displaying related entries
From PixyWiki
Contents |
Overview
For viewers of your blog it can be useful to display a list of related entries to a specific entry. This can be done in a couple of ways; either by using the Macro to display a list of related entries or by using the $model object.
Using the Macro
The macro is simple to include in your page templates and displays a list of the related entries. See the #showRelatedWeblogEntriesList documentation for details and an example.
Photoblog Example
For photoblogs, it can be useful to display a thumbnail image in-place of a text link.
Note: If you are on an entry page, as specified by the URL, then you can get the $entry object from the $model like so:
#if ($model.permalink)
#set($relatedEntries = $model.getRelatedWeblogEntries($model.weblogEntry, 5) )
<div>
#foreach ($relatedEntry in $relatedEntries)
#set($image = $relatedEntry.image)
#set($thumb = $image.thumbSquare)
<span>
<a href="$url.entry($relatedEntry.anchor)" title="$relatedEntry.title"><img src="$url.photo($thumb.path)" width="$thumb.width" height="$thumb.height" alt="#showImageAltTag($image)" /></a>
</span>
#end
</div>
#end
Otherwise, for non-entry pages, use the following code:
#set($entries = $model.weblog.getRecentWeblogEntries('nil', 1))
#foreach( $entry in $entries )
#set($relatedEntries = $model.getRelatedWeblogEntries($entry, 5) )
<div>
#foreach ($relatedEntry in $relatedEntries)
#set($image = $relatedEntry.image)
#set($thumb = $image.thumbSquare)
<span>
<a href="$url.entry($relatedEntry.anchor)" title="$relatedEntry.title"><img src="$url.photo($thumb.path)" width="$thumb.width" height="$thumb.height" alt="#showImageAltTag($image)" /></a>
</span>
#end
</div>
#end
Output
Using the demo blog the following is the output from the above code:


