Используя указанную вами ссылку, я разработал быстрый модуль для отображения случайного узла для данного термина таксономии в блоке. Если у вас есть собственный модуль, вам может понадобиться только часть, указанная в get_block_content()
. Модуль называется * test_block *, и эти файлы находятся на сайтах / all / modules / test_block
test_block.info
name = Test Block
description = Display a random block for given taxonomy term(s)
dependencies[] = node
core = 6.x
test_block.module
<?php
/**
* Implementation of hook_block()
*/
function test_block_block($op='list', $delta=0, $edit=array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t("Random Node Block");
return $blocks;
case 'view':
$blocks['subject'] = t("Random Node Block");
$blocks['content'] = get_block_content();
return $blocks;
}
}
/**
* Return the HTML teaser of a random node
* for a given taxonomy term
*/
function get_block_content() {
// Comma separated lists of terms tid to display nodes
$terms = '4,6';
$sql = "SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ($terms) AND n.status = 1 ORDER BY RAND() LIMIT 1";
$nid = db_result(db_query($sql));
if ($nid) {
// Return the node teaser
return node_view(node_load($nid), TRUE);
}
return t('No nodes available for the term(s) given.');
}
Дополнительные параметры отображения узла см. node_view()
.