使用templates 自定user 頁

終於來到預定的templates 最後一章
這次只是給多一個例子給大家參考
並沒有新的技術, 函數要認識, 使用

在一個用戶登入之後,
預設會到逹 user/[uid] 頁面
今次的目的就是改動這個頁面
例如:

  • 令登入都立即看到自己建立的nodes ( 配合使用views )
  • 不同的登入id 使用不同的頁面
  • 不同的roles 使用不同的頁面
  • 不同的profile fields(例如"城市")到不同的頁面

等等
建立社區主導的網站應該會使用到這個教學

因為url 為 user/[uid]
很有機會相關的輸出都是來自user/module
打開user/module, 到 user_menu() 函數
line 810 的 'path' 為 user/arg(1)
callback 到 user_view() 函數

line 1504 user_view(), 最後的一句:

<?php
 
return theme('user_profile', $account, $fields);
?>

找到了

到 user.module 內的 line 654, theme_user_profile()
將內裏的內容放到新建的 user_profile.tpl.php
'return' 改為 'print'
template 文件(user_profile.tpl.php) 放到你的theme 的目錄之下
user.module 的部份完成

到template.php 了, 打開你的theme 之下的template.php
新建一個函數, [theme_name]_user_profile()

<?php
function joe2_user_profile($account, $fields) {
  return
_phptemplate_callback( //此函數令drupal 找*.tpl.php
   
'user_profile', //找user_profile.tpl.php 文件來使用
   
array( 'account'=>$account , 'fields'=>$fields ), //傳給 user_profile.tpl.php
   
array( 'user_profile_'.$account->uid ) //根據你的特別要求, 使用不同的template, 注(一)
 
);
}
?>


注一:
這個例子建議使用user_profile_[uid].tpl.php (如有)
你也可以使用:
<?php
   
array( 'user_profile_'.$account->role )
?>

建議使用user_profile_[role].tpl.php (如有)

可以再配合template redirect, 轉到views 頁面等等,
就看你的創意了

以後要自定user 頁,
只要修改user_profile.tpl.php 就可以了

Comments

有沒有一些用來製作討論區的模組/版面是值得推介?

你的user uid 的資料很有用, 遲些可以試試,
不過有問題想問你.......

剛剛認識 Drupal 的時候, 是用4.7, 為了令Drupal的討論區出色一點,
所以用了flatforum模組.
雖然分類上flatforum是版面, 但其實它是不錯的模組.
例子網站:
http://www.zv-magazine.be/forum
[自己只在localhost試, 所以無法顯示出來]

到真正用Drupal 開發機構網站時, 自然升級為5.1, 5.2
但 flatforum 模組的所謂 5.0版本 -> [flatforum CVS]
http://drupal.org/node/95590
已經一早說明 Compatible with Drupal 5.0, but not with the garland theme
而自己真的用這 flatforum CVS的時候, 不但 garland 版面不能使用, 自己開發的版面,
比較漂亮/特別的版面, 全都作廢.

有沒有一些類近 flatforum模組/版面,
可以讓我建立一個比較好一點的討論區.
[比Drupal內建那個好, 而又不用再新增多一個討論區系統,
(例如: phpbb, vBulletin forum 等)
現在機構內的網站太多資料庫(database)]

抱歉,

抱歉, 因為沒有使用過這個模組,
所以也沒有辦法到你
但你可以使用以上相同的方法,
找出theme_* 的函數, 然後修改

Translation

Any chance of getting an English translation.

模組 taxonomy theme 在討論區中失靈

不用抱歉, 終於很辛苦地把node-forum.tpl.php 拿來改看看,
現在討論區樣子還不錯.不過, 我有3個討論區分區,
Band, Graffiti, 和 一般討論.

而我有3個版面(theme), band_forum, graffiti_forum, 和 ho_forum.

我已經安裝 taxonomy theme, 也 assign 不同版面到不同討論區.
band_forum 版面 => Band 討論區
graffiti_forum 版面 => Graffiti 討論區
ho_forum 版面 => 一般討論區
網頁本身是 ho_forum 版面

forum_theme1.jpg

但是.........問題出現了
首頁很正常地顯示 ho_forum 版面
forum_theme2.jpg

入到Band 討論區[甚至發表新主題的版面], 也很正常地顯示 band_forum 版面
forum_theme3.jpg

但Band 討論區裡面的貼子[屬於Band 討論區], 卻顯示 ho_forum 版面........怎算好
forum_theme4.jpg

看了那個貼文為何應

看了那個貼文為何應該跟band_forum 版面會變成 跟 ho_forum,
因為貼文是預設為 "系統預設", 而不會跟所選擇的討論分區,
強行設定你的文章是跟那個版面.............

forum_theme5.jpg

怎樣可以令讀者選了某個討論區,
drupal 便自動設定你的文章是跟那個版面.
[例如: 選了Band 討論分區, 便自動設定你的文章
是band_forum 版面]

首先, 為了版面整潔,

首先, 為了版面整潔, 去掉了圖, 只留下link

有關預設為某一taxonomy, forum 下都有一個"add a new post"
這個link 是可以令新的post 自動設定到一個taxonomy 的, 你可以參考一下

怎樣用pathauto令 node/1, node/2 變 [tid]/1, [tid]/2, 或者band/1, band/2

多謝你, 但我有另一條問題...........
如果我有一個討論區,
有3個分版, aa, bb, cc.
它們的tid分別是2,3,4
[在討論區的連結自然是forum/2, forum/3, forum/4]

而當然有一些貼文,
node/7, node/8, node/11 是屬於 分版aa
node/6, node/9 是屬於 分版bb
node/10, node/12 是屬於 分版cc
如果我想那些貼文, 屬於那個分版, 便用那個分版名, 為folder名,
或者這樣說, 如果我想把 那些node變成
node/7, node/8, node/11
變成
tid/2/1, tid/2/2, tid/2/3
或者
aa/1, aa/2, aa/3
或者
aa/7, aa/8, aa/11

node/6, node/9
變成
tid/3/1, tid/3/2
或者
bb/1, bb/2
或者
bb/6, bb/9

如此類推.

我要怎樣改pathauto?? 因為不論怎樣改也沒有反應.
是否一定要開 clear-url???

Node path settings, Category path settings, User path settings
都不知應該改那個.........才達到我的目的.

pathauto

pathauto 看怕內建的功能做不到
要改pathauto 的code
但這要求奇怪
因為一般的論壇都要不會有這樣的功能
一, 為了seo
二, 為了改分區名的時候的方便
細想一下看看

尚算解決了,

尚算解決了, 在drupaltaiwan貼了教學

求救!求救! taxonomy theme 無法完全assign 某版面到某討論區
http://drupaltaiwan.org/forum/20070820/1466

怎樣用pathauto令 node/1, node/2 變 [tid]/1, [tid]/2, 或者band/1, band/2
http://drupaltaiwan.org/forum/20070828/1482

不論進入, 或是留言, 或是回應, 都會是不同討論區分版, 見到不同版面.

不過修改已發表的留言時, 會回歸到最原本預設的版面........這個叫我頭痛...........
[因為修改的連結是?q=node/1/edit , 而不是 ?q=band/1/edit]
求救尚未完成...........

Yep, an English translation

Yep, an English translation would be great :-)

Excellent blog, do you allow

Excellent blog, do you allow your posts to be republished?

Yup. please post this link

Yup. please post this link before the republished content.

hey thanks for sharing good

hey thanks for sharing good job keep it up

thx~ just keep coming or

thx~
just keep coming or subscribe this site's feed!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <h4> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options