Drupal块回调示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Drupal块回调示例相关的知识,希望对你有一定的参考价值。

This is a callback example that can be used to conditionally display blocks on specific pages. In this example, I load all nodes with a specific field and return false if the value of that field is equal to the user id of the logged in user. The snippet in it's entirety probably won't be helpful, but it contains functions that have many applications.
  1. <?php
  2.  
  3. if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) { # if is node
  4. global $user; # get info of logged in user
  5. $nid = arg(1); # define node id
  6. $node = node_load($nid); # load node info
  7.  
  8. $items = field_get_items('node', $node, 'FIELD_LABEL_HERE', $node->language); # get nodes by field value
  9. if($items) {
  10. foreach ($items as $item)
  11. {
  12.  
  13. # loop through matching nodes
  14. # Example below: if a matching node has a field value equal to the uid of the logged in user, return false
  15. if($item['target_id'] == $user->uid) { return false; }
  16.  
  17. }
  18. }
  19.  
  20. }
  21.  
  22. ?>

以上是关于Drupal块回调示例的主要内容,如果未能解决你的问题,请参考以下文章

Javascript代码片段在drupal中不起作用

Drupal 6 视图 2:PHP 片段

Sphinx - 在代码块片段中使用省略号 (...)

Drupal:在代码区域中插入块

回调函数示例

按分类过滤内容类型的 Drupal 块