내가 제공 한 링크를 사용하여 블록의 주어진 택 소노 미 용어에 대해 임의의 노드를 표시하는 빠른 모듈을 만들었습니다. 자신의 모듈을 가지고 있다면, get_block_content()
에 주어진 부분 만 필요할 것입니다./모든/모듈/test_block
자세한 내용은 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.');
}
name = Test Block
description = Display a random block for given taxonomy term(s)
dependencies[] = node
core = 6.x
test_block.info 모듈은 * test_block의 *라고하며,이 파일은 사이트 내에 위치 노드 디스플레이의 옵션은 node_view()
고맙습니다! 매력처럼 작동합니다. – Sprachprofi