Drupal API 制作首页

    技术2025-04-08  28

    1.在template.php中添加函数phptemplate_show_frontpage():

     

    function phptemplate_show_frontpage(){ //获取vocabulary为1的terms $taxtree = taxonomy_get_tree(1,0); //设置首页每个单元的节点个数为5 variable_set('feed_default_items', 5); foreach($taxtree as $tax){ $output .= "<div><h2>". l(taxonomy_get_term($tax->tid)->name, "taxonomy/term/$tax->tid")."</h2><ul>"; //$pager为false时利用以上全局变量feed_default_items限制节点个数 $result = taxonomy_select_nodes (array($tax->tid), 'or', 0,false);//echo typeof($nodes); while($node = db_fetch_object($result)){ $output .= "<li>".l($node->title,"node/$node->nid")."</li>"; } $output .= "</ul></div>"; } return $output; }

     

    2.在自定义themes目录下创建page-front.tpl.php文件:拷贝page.tpl.php到page-front.tpl.php,将:

    <?php print $content ?>

    替换成:

    <?php print phptemplate_show_frontpage(); ?>

    最新回复(0)