You are here

Display none title(我写的小模块,)

g089h515r806 的头像
Submitted by g089h515r806 on 星期一, 2009-06-22 05:02

有时候,你不想显示一个特定的节点标题,就像区块标题一样,你想在标题栏中输入一个<none>,通过这样来不显示标题,事实上,这是不行的。

如果不想显示特定节点的标题,通常的做法就是单独的为这个节点创建一个页面模板文件,比如这个节点的id为108,那么模板文件就为: page-node-108.tpl.php.

在这个模板文件中,你可以删除title变量,我们以最常用的garland为例,在模板文件的中间有这样一段:

 <?php print $breadcrumb; ?>
          <?php if ($mission): print '<div id="mission">'. $mission .'</div>'; endif; ?>
          <?php if ($tabs): print '<div id="tabs-wrapper" class="clear-block">'; endif; ?>
          <?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>
          <?php if ($tabs): print '<ul class="tabs primary">'. $tabs .'</ul></div>'; endif; ?>
          <?php if ($tabs2): print '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
          <?php if ($show_messages && $messages): print $messages; endif; ?>
          <?php print $help; ?>
          <div class="clear-block">
            <?php print $content ?>
          </div>
          <?php print $feed_icons ?>
          <div id="footer"><?php print $footer_message . $footer ?></div>

我们需要把这段  <?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>删除。
这样,这个节点的标题就不显示了,无论你在标题栏中,输入什么,他都不显示。

当然,如果还有其他的节点,比如说,节点46,68等等,他们的标题也不想显示,怎么办呢?通过上面的方法也可以实现,那就是再创建两个模板文件,但是有一点,你修改了page.tpl.php,那么你需要同时修改这些模板文件,这是这种方式的不足。

还有一种方式,就是在phptemplate_preprocess_page(&$vars)中进行控制,有多种方式。这里就不介绍了,这里介绍通过模块来控制:

<?php
// $Id$

/**
 * @file
 * Not display title for none title.
 */

function none_title_preprocess_page(&$vars){

 if($vars['title'] =='&lt;none&gt;'){
   unset($vars['title']);
  }
 
}

 

上面是我写的小模块,很容易就实现了本文开头所说的效果,用户只需要在标题栏中,输入一个<none>,这样就不用显示标题,和区块的标题,效果一样,当然你也可以把模块中的代码拷贝到你的template.php文件中。效果是一样的。