Hereafter is the new version of the GetCategoryLink snippet:
<?php
/*
* Get the link to a category product
*
* &tplid : the template id of the category product
*
* &id : any document id
*
* Explore the parents of a document to search the category product
* if the category product is found, return the link to this document
* otherwise return the link to the current document
*
*/
if(!function_exists('findIt')) {
function findIt($cid, $tplid, $id) {
global $modx;
$parent = $modx->getParent($cid,1,'id, template'); // get parent infos
if ($parent) {
if ($parent['template'] == $tplid) $ctgid = $parent['id']; // eureka!
else $ctgid = findIt($parent['id'], $tplid, $id); // go up!
}
else $ctgid = $id; // parent not found
return $ctgid;
}
}
$tplid = (isset($tplid)) ? $tplid : 0;
$id = (isset($id)) ? $id : $modx->documentIdentifier;
$ctgid = findIt($id,$tplid,$id);
$url = $modx->makeUrl($ctgid);
echo $url;
?>
For a document if a parent document has a template with a specific number, then the link to this parent document is returned otherwise the link to the current document is provided.
In your result template you need to call it as follow:
<a class="[+as.resultLinkClass+]" href="[[GetCategoryLink? &tplid=`8` &id=`[+as.id+]`]]" title="[+as.longtitle+]">[+as.pagetitle+]</a>
Where &tplid is the template number of your category document.
What kind of beer do you drink?
In front of the gulf St Vincent, any beer