getOption('tpl', $scriptProperties); $limit = $modx->getOption('limit', $scriptProperties, 5); $tvname = $modx->getOption('tvname', $scriptProperties, "autotag"); $tvvalue = $modx->resource->getTVValue($tvname); $base = $base = $modx->config['base_url']; $currentid = $modx->resource->id; $output = ''; $q = $modx->newQuery('modResource', array( 'context_key' => $modx->resource->context_key, 'parent' => $modx->resource->parent )); $q->select('pagetitle,introtext,publishedon,uri,tvres.value as autotag'); $q->innerJoin('modTemplateVarResource', 'tvres', "tvres.contentid = modResource.id"); $q->innerJoin('modTemplateVar', 'tv', "tv.id = tvres.tmplvarid"); $q->limit($limit); $q->where(array( 'modResource.id:!=' => $currentid, 'tv.name' => $tvname, 'tvres.value:REGEXP' => str_replace( ',', '|', $tvvalue) ) ); if($q->prepare() && $q->stmt->execute()) { while ($row = $q->stmt->fetch(PDO::FETCH_ASSOC)) { $output .= $modx->getChunk($tpl, array( 'url' => $base.$row['uri'], 'date' => date("Y-m-d H:i:s", $row['publishedon']), 'pagetitle' => $row['pagetitle'], 'text' => $row['introtext'] )); } } return $output; /*Здесь, я выбираю записи из таблицы с классом modResource, с которыми связана автометка имеющая, хотя бы одно значение, такое же как у текущей. Вызов: [[!tagRelated:default=`Пока нет связанных постов`? &tpl=`RELATED` &limit=`4` &tvname=`autotag` ]] Чанк RELATED:
*/