Drupal7 中隐藏某种类型的node 中的字段

1.根据Content Type 的机器名称,复制一个node.tpl.php的文件 重命名为 node--machinename.tpl.php.

2.安装Devel 模块。用于查看相关的字段名等

3.加入代码:

<div class="content clearfix"<?php print $content_attributes; ?>>
    <?php
      // We hide the comments and links now so that we can render them later.
      hide($content['comments']);
      hide($content['links']);
        if(strpos($_SERVER['HTTP_USER_AGENT'],'iPad')||strpos($_SERVER['HTTP_USER_AGENT'],'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'],'iPod')||strpos($_SERVER['HTTP_USER_AGENT'],'iTouch'))
        {
           // define("IS_IOS",true);
            hide($content['field__iap_dl']);
            
        }
        else
        {
          //  define("IS_IOS",false);
           hide($content['field_ios_install']); 
        }
       
      print render($content);
    ?>
  </div>

这段代码是更加用户的访问设备,如果是苹果移动设备的话,隐藏一个字段,不是的话隐藏另一个字段。

判断设备的代码 http://stackoverflow.com/questions/6322112/check-if-php-page-is-accessed-from-an-ios-device

原文地址:https://www.cnblogs.com/igoogleyou/p/druaplfield.html