Drupal

Tabbed Block

This is a module that you can embed different blocks into one with tabs.
Those tabs switch with javascript based on jquery, shorten your sidebars without reducing the content of your page.

The offical homepage on drupal.org is opened:
http://drupal.org/project/tabbed_block
The below svn is outdated, please use files on Drupal.org, and svn will dropout from the site soon.

svn address: http://www.joetsuihk.com/svn/drupal_modules/tabbed_block/trunk

這個模組可以將多個區塊整合到一個之中,
並使用jquery 這個javascript 庫來幫助使用者瀏覽
令你的左右兩邊的導航條縮短但又不用放棄某些內容

這模組已經放到 Druapl 主站上的模組專頁:
http://drupal.org/project/tabbed_block
下面的svn 已經不會再更新, 請到drupal.org 內查看更新

svn 地址: http://www.joetsuihk.com/svn/drupal_modules/tabbed_block/trunk


[views 2.0 版] 使用 views 建立tabs, use view to build tabs

tabs 一直是Drupal 中比較少特別提及的功能之一
用戶頁 user/[uid] 便是一個很標準的tab 應用
"view"/"edit" tab 也常見於node 頁

使用views 可以很方便的建立tabs
前文Drupal 5 版: http://www.joetsuihk.com/node/112 中已經介紹過
那是Drupal5, views1 的版本
這次介紹 Drupal6, views2 的版本的設定方法

這次是建立一個tab
顯示用戶建立的node 之中, 留言數目大於10 的頁面, 定義為 "hot"
路徑 user/[uid]/hot
如圖:

我從內建的 tracker 模組的views 開始,
用 clone, 建立一個新的views,
其中, page 的設定:

page settings: 選menu tab
(Default meni tab 是作為預設顯示時才用, 如路徑 user/[uid] )
之後設定頁面的Title, 便完成了

將搜尋結果排序

最近做的一件案子中,
有一個比較少見但有時候很實用的功能需求
就是要將搜尋的結果以某條件排序
例如搜尋一些新聞, 時間性很重要
想要將最近相關的新聞排先, 以日期順序
但內建的搜尋是以相關性排序, 最相關的排先

思路:
首先是排序
排序首選是views
但views 的 filter 過濾器並沒有搜尋相關字的設定
但使用views table 排序是最方便的
views 自己就內建

所以我要將搜尋的結果傳給views
自然是使用 arguments 了
找出搜尋結果的nid, 再用逗號分隔, 傳給views
再將views 內嵌到serach result 的頁面

實際解決辦法, 設定:
先新增一個views,
顯示設定為table, 可排序
再到fields 選擇所需的欄位
重點在argument 的欄位,
選Node:nid
Provide default argument
PHP code:

<?php
$results
=node_search('search',arg(2));
 
$size = count($results);

  for(
$i=0;$i<$size;$i++){
    if (
$i+1==$size){
     
$output .= $results[$i]['node']->nid;
    }else{
     
$output .= $results[$i]['node']->nid.",";
    }
  }
return
$output;
?>

Argument type: Node id separated by , or +
選中 Allow multiple terms per argument.

結語:
需然這個方法不是很完美(實際上這是做了兩次一樣的搜尋)
但既然主機的能力不是問題, 開發時間也不多
完成任務還是最重要的

[2009-01-12] Drupal localhost 多站開發, Drupal localhost multi-site config

作為一個 Drupal developer, 通常都有幾個開發同時進行
一般人可能會用htdocs/[folder] 名
例如 http://localhost/drupal6, http://localhost/drupal5
或者案子名 http://localhost/blog 等等
但萬一core 要更新, 或者cck, views 有更新
便要更數個站, 實在麻煩

大家都或者知道 Drupal 是可以設定 multi-site 的
即是, 同一套code 可以供給兩個站使用 ( 例如 example1.com 和 example2.com )
優點很簡單, 模組更新的時候, 只要更新一次便可以令兩個完全不相關的 Drupal 站更新模組
而兩站可以使用完全不同的模版, 完全不同的資料庫
只是共用 core 和某些常用的模組 (例如views, cck 之類)

你的 drupal-root 內的 sites 資料夾,
可以建立 all, example1.com, example2.com 等等的資料夾
all 內的 modules, themes 是供放多站共用的資料
而 example1.com 內也可以建立 modules, themes 資料夾, 放這個域名專用的模組

所以現在只要將某個domain 指到 localhost
便可以實現 http://blog.localhost/drupal6, http://shop.localhost/drupal6.........

到 C:\WINDOWS\system32\drivers\etc\hosts
127.0.0.1 blog.localhost
127.0.0.1 shop.localhost
...
..

再在 htdocs/drupal6/sites/blog.localhost/ 內建一個 settings.php 便可以了
便可以 http://blog.localhost/drupal6/install.php

相關資源
http://drupal.org/getting-started/6/install/multi-site

一次 untar 多個files

我現在多是用到sites/all/modules 用 wget 更新模組的
wget [url]
因為快, 又免了upload 的麻煩
複製了 drupal.org 內模組的下載url
貼到putty
但untar 不可以用萬用字符 *

find [folder] -iname "*.tar" -exec tar xvfz {} \;

google 大神果然最強!

使用 views 建立tabs, use view to build tabs

上圖顯示了一個經過修改的 user page 的 tabs

tabs 其實來自一個 hook(), menu_local_tasks()
用 theme developer 指一下便可以看到
但這次介紹的並不是要修改這個 hook 的 theme template
而是使用 views, 新增一個tab 到這個地方

在上圖的例子,
一個 url 為 [root]/user 的 頁面,
要在 views 建立一個的 tab, >Read more

使用regions 的要訣

在Druapl 中有關自定義regions,
使用panels 等等
有關將一個頁面分割為不同的部份,
以方便管理的技術, 這裡都有介紹過
但也因為有這兩種方法
我自己也一直想不通,
什麼時候使用panels, 什麼時候使用regions

後來, 為了效能的問題, >Read more

print.css

Drupal 內的一個常用的theme, Garland
經常給我用作範本, 東改改西改改成為一個新的theme
因為他左右sidebar 都可以, header, template.php 變數都很齊備
這次簡單說明一下theme 內的print.css >Read more

導覽

這是一個導覽node
因為"Drupal 教學" 這個book 已經越來越大
資料也越來越多
所以這一個置頂頁是給初學者一個快速的索引
列出首先應該看的幾個篇章

到進階時再看其他的進階教學

Theming 模版雜燴

Theming 的其中一個難題一定是多瀏覽器支援的問題
巿佔最高的品牌不跟足標準, 幾乎每一個瀏覽器都"think different"
難倒, 抓狂不少開發者
但既然每一個開發者都面對這樣的問題,
在這個web2.0 的時代就自然有解決的方法

下面是一些CSS 的 framework
這些framwork 就像drupal 內建的jquery 一樣
集合一些難纏的CSS, 變作一個框
你再將你自己的內容放到裏面就可以了
用作開發新的主題應該很合用

YAML builder
一個實用的WYSIWYG framework
可以自定一些常用的元素進去
http://builder.yaml.de/

Yahoo 大廠的出品
使用不簡單, 英文說明為主
http://developer.yahoo.com/yui/grids/#available-templates

Intensivstaion
一些已經建好的常用layout
http://www.intensivstation.ch/en/templates/