[inmediahk] use of views argument: 作者最新文章

這也是一個少見的要求,
但也相當合理
便是要在node 頁面(node/[nid])的右面欄加一個block, 用作顯示這個node 作者的其他文章
一個多用戶參與寫作的網站便很需要用這些block 來列表特定用戶的文章

這個當然不可能給每一個用戶都做一個views
用戶數是有三萬以上的...
正解也簡單, 始終是views

我想views 的 argument 一開始的理念就是由這類的網站需求帶動的
由url 路徑作參考, 修改views 的過濾器
但這次的url 是node/[nid], 並沒有uid 的資料, 所以還是要花點功夫在php 上
在argument type, 以 user UID is author
然後我們就可以想辦法將uid 傳給views
我們只有NID 可以使用,
便唯有將整個node 用node_load()
再從中抽出UID

argument handling code

if ($view->build_type == 'block' && arg(0) == 'node' && is_numeric(arg(1))) {
  $node=node_load(arg(1));
  $args[0] = $node->uid;
}
return $args;

Comments

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