欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal 主题 函数例子 theme_item_list theme_links l 函数

shiping1 的头像
下面这在个函数默认都会给当前的路径加上 class为active的属性
1)theme_item_list
  
表示 输出一个 ul 其 class='item_list'
其中 li 里面的东西就是 $links

$query = "select nid,title,created from {node}";
             $queryResult = db_query_range($query, 0 ,10);
             $links = array();
             while ($node = db_fetch_object($queryResult))
             {
                 $links[] = l($node->title,'node/'.$node->nid);
             }
             $block['content'] = theme('item_list', $links);

2)theme_links

function theme_links($links, $attributes = array('class' => 'links')) {

https://api.drupal.org/api/drupal/includes!theme.inc/function/theme_links/6
print theme('links',$primary_links, array('id'=>'site_menu'));
    
    //$primary_links 是主导航接组成的数组
            array(3) {
          ["menu-144"]=>
          array(3) {
            ["attributes"]=>
            array(1) {
              ["title"]=>
              string(0) ""
            }
            ["href"]=>
            string(27) "http://www.drupalstudy.shi/"
            ["title"]=>
            string(6) "首页"
          }
          ["menu-145"]=>
          array(3) {
            ["attributes"]=>
            array(1) {
              ["title"]=>
              string(0) ""
            }
            ["href"]=>
            string(32) "http://localhost/drupal/node/10 "
            ["title"]=>
            string(9) "毛太祖"
          }
          ["menu-146"]=>
          array(3) {
            ["attributes"]=>
            array(1) {
              ["title"]=>
              string(0) ""
            }
            ["href"]=>
            string(30) "http://localhost/drupal/node/8"
            ["title"]=>
            string(9) "邓太宗"
          }
        }

3)l 函数

$vars['link_comment'] =  l($vars['node']->links['comment_comments']['title'], $vars['node']->links['comment_comments']['href'],
               array(
                 'attributes' => array('class' => 'comment', 'title' => $vars['node']->links['comment_comments']['attributes']['title']),
                   'fragment' => $vars['node']->links['comment_comments']['fragment']
               )
普通分类: