显示标签为“drupal”的博文。显示所有博文
显示标签为“drupal”的博文。显示所有博文

2009年2月21日星期六

建立节点类型node-type模板

在默认安装的drupal后,安装程序会创建2个内容类型:page和story。所有的节点内容输出都是通过node.tpl.php完成,无论是在摘要(teaser)页还是内容页(page)。

如果需要我们可以每个内容类型或单个内容类型建立节点(node)模板,例如:
node-story.tpl.php

推荐方法是:复制主题模板目录中的node.tpl.php另保存为:node-story.tpl.php
注意:node.tpl.php必须在你的主题目录中,不要将node.tpl.php重命名为node-story.tpl.php

如果你还有其他内容类型需要定制,规则是:node-[node-$type].tpl.php
什么是node-$type?你可以URL到admin/content/types 查看。
加入你启用了forum和book模块,可以建立:node-forum.tpl.php 、node-book.tpl.php

建立node-[node-$type].tpl.php不是必须的,根据需要定制,如果大同小异就没有必要了。

另外在drupal 6.x中,当建立了新的模板文件需要注册,方法是在"管理--> 站点设置-->性能" URL:admin/settings/performance 点击"清除缓存数据"按钮

  • 本文的介绍内容你可以访问:http://drupal.org/node/17565
  • 关于Node.tpl.php可以参考drupal.org的文章http://drupal.org/node/11816

建立node-1.tpl.php这样的模板

在使用drupal建站时,可能会遇到单独定制某个节点模板的需要,(例如想建立node-1.tpl.php这样的模板)在drupal.org找到了相关的解决办法。

需要复制或合并代码到你的主题模板的template.php

drupal 6.x

<?php
function phptemplate_preprocess_node(&$vars) {
    $vars['template_files'][] = 'node-' . $vars['nid'];
    return $vars;
}
?>

Drupal 4.7.x 和 Drupal 5.x

<?php
function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'node':
      $vars['template_files'] = array('node-'. $vars['nid']);
      break;
  }
  return $vars;
}
?>

然后复制node.tpl.php另存为:node-[nodeID].tpl.php (例如:node-1.tpl.php)根据自己的需要修改。 原文链接:Separate node template for a specific node

2009年2月18日星期三

drupal6.x分页风格仿digg

闲来无事修改drupal6.x分页风格仿digg,效果如下:

drupal_6x_pager_digg_skin_001
drupal_6x_pager_digg_skin_002
drupal_6x_pager_digg_skin_003

CSS代码:

/* 注意:保证以下代码不被默认的代码覆盖
 如果有冲突自行修改
----------------------------------------------- */

/* container
 在低分辨率下(如:800x600)使用默认garland主题时
 防止分页超出页面宽度换行,你可以根据情况注释掉
----------------------------------------------- */
#container{
 width: 980px;
}

/* pager
----------------------------------------------- */
div.item-list ul.pager{
 padding: 0px;
 margin: 1em 0;
 clear: left;
 text-align: center;
 font: 12px/1.4em Arial, Helvetica, sans-serif;
}

div.item-list ul.pager li{
 background-image:none;
 display:inline;
 margin: 0px;
 padding: 0px;
 list-style: none;
 border: none;
}

div.item-list ul.pager a.active,
div.item-list ul li.pager-current,
div.item-list ul li.pager-ellipsis{
 background: #fff;
 text-decoration: none;
 border: 1px solid #9AAFE5;
 color:#105CB6;
 display: block;
 float: left;
 padding: .2em .5em;
 margin-right: 1px;
 cursor:pointer;
}

div.item-list ul li.pager-ellipsis{
 border: none;
 color:#333;
}

div.item-list ul.pager li .active:hover {
 border: 1px solid #2E6AB1;
}

div.item-list ul.pager li.pager-current{
 border: 1px solid #2E6AB1;
 font-weight: bold;
 background: #2E6AB1;
 color: #fff;
 margin-right: 1px;
}

2009年1月19日星期一

drupal5.x的files表和file_revisions表

内容主要记载自己当前一些理解

drupal5.x的files表

  • fid
  • nid
  • filename值:如DSCF2976.jpg
  • filepath值:如sites/default/files/images/DSCF2976.jpg
  • filemime值:如image/jpeg
  • filesize

file_revisions表

  • fid值对应fid
  • vid值对应nid
  • description值在附件列表显示的信息
  • list值0或1

附件上传的信息全部保存在files表,如果需要在系统附件注册,将附件写入file_revisions表

2009年1月14日星期三

不加载模块带的css文件

制作调试Dupal主题时经常会遇到系统模块自带的css文件带来的麻烦,最初的做法是从新定义相关的样式属性,后来看到Advanced Theme Construction Kit (ATCK)才长了见识,会发现原来可以这样。

来学习怎样不加载模块带的css文件

一、在主题的template.php中增加:

function atck_styles() {
 $css = drupal_add_css(path_to_theme() .'/page-layout.css', 'theme', 'all');
 $css = drupal_add_css();
 unset($css['all']['module']['modules/node/node.css']);
 unset($css['all']['module']['modules/system/defaults.css']);
 unset($css['all']['module']['modules/user/user.css']);
 return drupal_get_css($css);
}

注意:如果你使用该代码测试,请将:
function atck_styles()替换为
function 你的主题名字_styles()

二、修改主题的page.tpl.php

将:<?php print $styles ?>替换为:<?php print 你的主题名字_styles() ?>

总结:

如果想不加载某个非drupal系统模块,如:tagadelic 模块,修改:

function atck_styles() {
 $css = drupal_add_css(path_to_theme() .'/page-layout.css', 'theme', 'all');
 $css = drupal_add_css();
 unset($css['all']['module']['modules/node/node.css']);
 unset($css['all']['module']['modules/system/defaults.css']);
 unset($css['all']['module']['modules/user/user.css']);
unset($css['all']['module']['sites/all/modules/tagadelic/tagadelic.css']);
 return drupal_get_css($css);
}

其sites/all/modules/tagadelic/tagadelic.css的路径是相对于base_path()
另外有点不明白作者为什么使用$css = drupal_add_css(path_to_theme() .'/page-layout.css', 'theme', 'all');来增加css文件,而不使用.info文件。
相关参考:drupal_add_css drupal_get_css path_to_theme()

2009年1月11日星期日

drupal_add_css的使用

API:http://api.drupal.org/api/function/drupal_add_css

drupal_add_css($path = NULL, $type = 'module', $media = 'all', $preprocess = TRUE)

增加CSS文件到风格队列

参数:
$path (可选的),CSS文件路径是相对base_path(),例如:/modules/devel/devel.css
$type (可选的),module 或 theme
$media (可选的) ,例如:all, print, screen.
$preprocess (可选的) Should this CSS file be aggregated and compressed if this feature has been turned on under the performance section?(看不懂)

例子:

function tagadelic_init() { drupal_add_css(drupal_get_path('module', 'tagadelic') .'/tagadelic.css'); }

2009年1月4日星期日

views的theme函数控制文章标题的输出长度

原文: http://drupalchina.org/node/3012#comment-8596

<?php
function  phptemplate_views_handle_field_node_title($fields, $field, $data) {
  $info = $fields[$field['fullname']];

  if ($field['handler'] && function_exists($field['handler'])) {
    $title = $data->$field['queryname'];
    if (drupal_strlen($title)>20) {
        $title = drupal_substr($title, 0, 20)."...";
    }
    return $field['handler']($info, $field, $title, $data);
  }

  if ($info['handler'] && is_string($info['handler']) && function_exists($info['handler'])) {
    return $info['handler']($info, $field, $data->$field['queryname'], $data);
  }

  return check_plain($data->$field['queryname']);
}
?>