2012-03-12 2 views
1

특정 택 소노 미에서 정확하게 임의로 선택된 노드의 티저를 보여주는 사용자 정의 블록을 원합니다. http://drupal.org/node/135344이 발견되었지만 일련의 노드 제목 만 표시합니다. 대신 임의의 노드 중 하나에 대해 티저를 표시하려면 어떻게해야합니까?Drupal 6의 사용자 정의 블록에 노드 티저 표시

저는 i18n을 포함한 Drupal 6을 사용하고 있습니다. 보기 모듈을 사용하고 싶지 않습니다. 왜냐하면이 모양을 많이 사용자 정의 할 계획이기 때문입니다. 초보자를 도와 주셔서 감사합니다!

답변

1

내가 제공 한 링크를 사용하여 블록의 주어진 택 소노 미 용어에 대해 임의의 노드를 표시하는 빠른 모듈을 만들었습니다. 자신의 모듈을 가지고 있다면, 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()

+0

고맙습니다! 매력처럼 작동합니다. – Sprachprofi

관련 문제