Работающая версия компонента modRelation, для вывода похожих статей. Исправлен неработающий функционал, добавлен параметр &limit. В компоненте всего один сниппет, поэтому можно даже не скачивать компонент, а использовать сразу этот код:
<?php
if (!$parents) {
$parents = 0;
}
$parents = $modx->getChildIds($parents, 10, array('context' => 'web'));
if (!$limit) {
$limit = 10;
}
if (empty($field)) {
$field = 'pagetitle';
}
if (empty($separator)) {
$separator = ' ';
}
if (empty($element)) {
$element = 'pdoResources';
}
if (empty($limitWord)) {
$limitWord = 4;
} else {
$limitWord = intval($limitWord);
}
$pagetitle = $modx->resource->get($field);
if (!$pagetitle) {
return;
}
$arr = explode($separator, $pagetitle);
$rand = array_rand($arr, 1);
//remove small words
foreach ($arr as $a) {
if (iconv_strlen($a) < $limitWord) {
continue;
}
//crop word
if ($substr) {
$a = mb_substr($a, 0, $substr, 'UTF-8');
}
$words[] = $a;
}
$count = 0;
//loop
if (count($words) < 1) {
return;
}
foreach ($words as $w) {
$count++;
$OR = ($count > 1) ? 'OR:' : '';
$q[] = [
$OR . $field . ':LIKE' => '%' . $w . '%',
'id:!=' => $modx->resource->id,
'parent:IN' => $parents,
'published' => 1
];
}
$properties = [
'limit' => $limit,
'where' => $q
];
$scriptProperties = array_merge($properties, $scriptProperties);
//$modx->log(1, print_r($arr, 1));
$pdoTools = $modx->getService('pdoTools');
$output = $pdoTools->runSnippet($element, $scriptProperties);
return $modx->setPlaceholders([
'output' => $output,
], 'modrelation.');