2009年1月22日星期四

新建一个VIEWS,同时输出多种样式的做法

原文链接:http://drupalchina.org/node/2984 原文作者:葬月 效果图:

需要修改加入template.php里的代码,如下:

function phptemplate_views_view_list_qzsy_zjdf($view, $nodes, $type) {
  $fields = _views_get_fields();

  $taken = array();

  // Set up the fields in nicely named chunks.
  foreach ($view->field as $id => $field) {
    $field_name = $field['field'];
    if (isset($taken[$field_name])) {
      $field_name = $field['queryname'];
    }
    $taken[$field_name] = true;
    $field_names[$id] = $field_name;
  }

  // Set up some variables that won't change.
  $base_vars = array(
    'view' => $view,
    'view_type' => $type,
  );

  $i = 0;              //添加的代码
  foreach ($nodes as $i => $node) {
    $vars = $base_vars;
    $vars['node'] = $node;
    $vars['count'] = $i;
    $vars['stripe'] = $i % 2 ? 'even' : 'odd';
    foreach ($view->field as $id => $field) {
      $name = $field_names[$id];
      $vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
      if (isset($field['label'])) {
        $vars[$name . '_label'] = $field['label'];
      }
    }
$i++;              //添加的代码开始
if($i == 1){ $items[] = _phptemplate_callback('views-list-qzsy_zjdf2', $vars); }  
else{            
$items[] = _phptemplate_callback('views-list-qzsy_zjdf', $vars);           
}                    //添加的代码结束
  }
  if ($items) {
    return theme('item_list', $items);
  }
}

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月16日星期五

颈椎病的相关参考认识

最近颈椎引发的疼痛和头晕越加频繁了,主要表现在后脑勺与脖子交接的部位,感觉里面有肿胀,还有背部两臂之间感觉有地方绊住似的,脊椎也有突出地方。自己也不是医生对这些部位描述的不详细。这些问题造成的主要原因还是与自己的工作和爱好有关,长期坐在电脑前,每天至少有10小时是在电脑前度过的,夸张的时候在15-18小时。家人也常唠叨我,但自己却不以为然,只能怪自己。

搜集一些对颈椎病的介绍和治疗、防治方法,希望对自己有所帮助

认识有关颈椎生理曲度的基本常识 “电脑依赖症”让脖子提前几十年老化 颈椎病分型及对症治疗 关于颈椎病,上班族必须知道的TOP5 网友评选的20条日常颈椎养护技巧 颈椎病患者颈椎锻炼四大简单方法 颈椎病保健体操 讨厌的职业病

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月7日星期三

使用Google文件发布Blog

Google文件 可以在线建立、撰写、储存和分享您的文档与电子表格。同时可以使用“在线文档”张贴到blog。

下面是Google帮助解释,原文--发布: 张贴到博客

设置BLOG帐号按下图红色箭头所示操作,点击“设置”

按下图红色箭头所示操作,编辑BLOG设置

根据你的BLOG类型选择博客服务,也可以自己定义

为了演示我选择的是blogger.com的博客

正确输入你的帐号后,返回到“Google 文档”。

按照下图点击“新建--> 在线文档”

新建的文档,默认标题是“无标题”,你点击它可以修改

按照下图所示,一次点“共享--依网页形式发布...”

按照下图所示把文档发布到博客中。

如果你的博客帐号设置正确,很快你的文章会发布到你的博客中,赶快试试吧!

2009年1月6日星期二

www.chinaw3c.org 问题不少

今天在w3.org转到www.chinaw3c.org,点击很多网页都打不开,更令我惊讶的是在其首页底部链接地址有错误。

2009年1月5日星期一

认识了解CSS2.1的font-family

'font-family'
Value: [[ <family-name> | <generic-family> ] [, <family-name>| <generic-family>]* ] | inherit
Initial: depends on user agent
Applies to: all elements
Inherited: yes
Percentages: N/A
Media: visual
Computed value: as specified

示例 1:

body { font-family: Gill, Helvetica, sans-serif }
<family-name>

在示例 1 中Gill 和 Helvetica 分别是字体的名字

<generic-family> 在示例 1 中 sans-serif 是一个字体序列

generic families的定义

  • 'serif' (e.g. Times)
  • 'sans-serif' (e.g. Helvetica)
  • 'cursive' (e.g. Zapf-Chancery)
  • 'fantasy' (e.g. Western)
  • 'monospace' (e.g. Courier)

serif 是指有衬线的字体,看:衬线体

sans-serif 是指无衬线的字体,看:无衬线体

无衬线体(Sans-serif) 有衬线体(serif)

衬线字体的衬线(红色部分)

Examples of fonts that fit this description include:

Latin fonts
Times New Roman, Bodoni, Garamond, Minion Web, ITC Stone Serif, MS Georgia, Bitstream Cyberbit
Greek fonts
Bitstream Cyberbit
Cyrillic fonts
Adobe Minion Cyrillic, Excelcior Cyrillic Upright, Monotype Albion 70, Bitstream Cyberbit, ER Bukinst
Hebrew fonts
New Peninim, Raanana, Bitstream Cyberbit
Japanese fonts
Ryumin Light-KL, Kyokasho ICA, Futo Min A101
Arabic fonts
Bitstream Cyberbit
Cherokee fonts
Lo Cicero Cherokee

sans-serif

AaBbCc 123

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']);
}
?>

用 CSS 将超出显示宽度的内容隐藏起来

一般的文字截断(适用于内联与块):

.text-overflow {
display:block;/*内联对象需加*/
width:31em;/*指定宽度*/
word-break:keep-all;/* 不换行 */
white-space:nowrap;/* 强制在同一行内显示所有文本,直到文本结束或者遭遇 br 对象。不换行 */
overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
text-overflow:ellipsis;/* IE 专有属性,当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/
}

对于表格文字溢出的定义:

table{
width:30em;
table-layout:fixed;/* 只有定义了表格的布局算法为fixed,下面td的定义才能起作用。 */
}

td{
width:100%;
word-break:keep-all;/* 不换行 */
white-space:nowrap;/* 不换行 */
overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
text-overflow:ellipsis;/* 当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/
}

需要注意的是,这个只对单行的文字的效,如果你想把它用在多行上,也只有第一行有作用的。 这个写法只有IE会有“...”,其它的浏览器文本超出指定宽度时会隐藏。

2009年1月2日星期五

ScribeFire创建blogger帐号时,需要设置API URL为https

ScribeFire创建blogger帐号时,需要设置API URL为https,而不是http。害的我认为我的Firefox有故障。还好搜了一下,果然找到解决办法,这就是网络,不懂就搜吧。