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

这里的技术是共享的

You are here

drupal 一些主题函数

shiping1 的头像
http://api.drupal.org/ 里面其实各种函数都有
l 函数


包前主题 模块 的 各种
theme函数好像既可用于模块 也可用于tpl.php模板文件,应该也可以用于template.php文件吧
$result = db_query_range('SELECT n.title, n.body, n.created
    FROM {node} n WHERE n.uid = %d', $uid, 0, 10);

theme('item_list', $links);//体会一下

表示 输出一个 ul 其 class='item_list'
其中 li 里面的东西就是 $links

_函数 表示是私有的



http://api.drupal.org

theme_item_link 这个函数是没有的

只有  function theme_item_list($items = array(), $title = NULL, $type = 'ul', $attributes = NULL)
这个函数 但是与这里的
theme('item_list', $links); 好像不是一回事
好像不是一回事





• $primary_links: 一个包含了一级链接的数组。可在“管理➤站点构建➤菜单”中定义它们。通常$primary_links通过函数theme('links')来定制输出的样式,如下所示:
<?php
    print theme('links', $primary_links, array('class' => 'links primary-links'))
?>

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) "邓太宗"
          }
        }

    l()函数能够生成<a href=”link”>这样的链接。
     $block_content .= l($links->title, 'node/'.$links->nid) . '<br />';
        $image =   l($image, $node->url,$options);


1)theme_links()
2)theme_markup()
3)theme_block();

应该在有些版本的devel模块 development中可以看到
http://api.drupal.org     也可以找各种theme函数;

三)theme函数网址 http://api.drupal.org/api/group/themeable/5
    四)重要的函数 theme() ;根据传来的变量寻找对应的函数
    theme('image',$path)...首先找theme_image函数,如果找到的话 就会
    调用theme_image($path)
    尽量使用 theme('image',$path) 尽量不使用 theme_image($path)
    再举个例子 <?php $user=user_load(array('uid'=>$node->uid)); ?>
          <?php print theme('username',$user); ?>
五)常用的theme函数 (这些函数要实践一下)
        theme_block      模块开发时用到
        theme_box        显示div里面是传来的内容,只是自动生成class 不能手动添加class
        theme_image     通常在使用cck 创建图像后,传路径过来得到img
        theme_item_list  输出ul li 传进来的是数组,数组里的每个元素放在li里
        theme_links     用于显示超链接 好像与l函数差不多() 形如<ul><li><a href="#">AA</a><a href="#">BB</a></li></ul>的形式
        //比如首页 l('Return to index page','<front>')
        theme_table     根据变量 输出带表头的表格
        theme_usename    输出带链接的用户名
    六)重写theme函数 theme函数调用机制(Hook机制)
       theme('username',$user)按下列顺序从所有文件中找
            theme-name_username()  //theme-name 是主题名
            比如主题名是mytheme 那么找 mytheme_username()
            theme-engine_username()//theme-engine 模板引擎名
            如果没有 找模板引擎 找 phptemplate_username()
            theme_username()
            如果没有 执行 theme_username() 输出结果
    七)重写在 自定义主题目录下的 template.php文件里
        例子//重写 _username     //$user不可以引用(&$user 至少在drupal 6 不可以)
            function phptemplate_username($user){
                return 'hello '.$user->name;
            }



http://hellodrupal.info/node/43       主题开发制作
http://drupal.org/node/190815#block-tpl  tpl.php文件

http://hellodrupal.info/node/45   page变量
    * $head_title: 页面标题。例如:  <title><?php print $head_title ?></title>
    * $head: 网站头部标记 (including meta tags, keyword tags, and so on). 这个还不是很清楚
    * $styles: 返回CSS文件
    * $scripts: JS文件调用
    * $body_classes: A set of CSS classes for the BODY tag. This contains flags indicating the current layout (multiple columns, single column), the current path, whether the user is logged in, and so on.
站点特征
    * $front_page: The URL of the front page. Use this instead of $base_path, when linking to the front page. This includes the language domain or prefix.
    * $logo: 网站的logo图,如果在主题配置里面设置了logo ,
    * $site_name: 站点的名词,如果在主题里面配置 开启或关闭某些页面元素的显示。
    * $site_slogan: 站点口号, 主题配置开启或关闭某些页面元素的显示,可以在主题配置下关掉。在site-information下面设置
    * $mission:站点mission,site-information下面设置。主题可以配置开启或关闭某些页面元素的显示。
导航
    * $search_box:  搜索功能,搜索框
    * $primary_links (array):  主导航
    * $secondary_links (array):  二级导航
 页面内容
    * $left: 左边区域
    * $breadcrumb:当前页面导航
    * $title: page title
    * $help:  
    * $messages:
    * $tabs:  
    * $content:  
    * $right:  
页面底部
    * $feed_icons:feed图标
    * $footer_message: 页脚信息,在后台设置。
    * $footer : 底部区域
    * $closure:   

* $title    //文章的标题
$front_page   //首面路径
$site_name  //
$breadcrumb  //面包屑
  
普通分类: