Drupal China
作者:Evance | 源文: Add some regions to node.tpl.php for drupal
本来是想翻译drupal Theme developer 的Regions in PHPTemplate的.
后来仔细看了看,好像有些部分比如说How to define custom regions已经相关的中文文章,比如说是Joe的regions.
但是要说明的是,上面的方法不适应于添加regions到node.tpl.php和comment.tpl.php,所以写了这篇文章哈。
以我的网站为例,我在为node页面添加一个regions(不是block喔。) 示例网址:
我想在node内容的右面添加一个regions,取名为node_inner_right

打开 /theme/your_theme/template.php 文件,如果你使用的theme没有这个文件[i]template.php[i]的话,手动建立一个。
定义一个function _phptemplate_variables() 函数,如果它已经存在的话,就直接使用它。 加入如下代码:
function _phptemplate_variables($hook, $variables) {
// loead the regions only for full views
if($hook == 'node' && !$vars['teaser']) {
//load region content assigned via blocks
foreach(array('node_inner_right') as $region) {
$variables[$region] = theme('blocks', $region);
}
foreach(array('node_inner_bottom') as $region) {
$variables[$region] = theme('blocks', $region);
}
}
return $variables;
}
ok,现在去/admin/build/block,就可以发现,多了一个名为“Node inner right”的regions。现在在那一个regions里面增加block了,比如说偶增加了一个google_ad-node inner right。

增加regions了,我们最终要让它显示在node里相应的位置。
因此,打开node.tpl.php,找到:
<?php
print $content
?>增加显示node_inner_right的代码:
<?php if ($node_inner_right && $page !=0) { ?>
<div id="node_inner_right"><?php print $node_inner_right?></div>
<?php }; ?>
至于是把regions放到$content前还是后,css怎么写,这个又是另外一个范畴了。本文介绍的仅仅是如何添加一个regions到node.tpl.php里面。
| 附件 | 大小 |
|---|---|
| node_inner_right_demo.gif | 40.68 KB |
| node_inner_right.gif | 6.69 KB |
好文章,支持老大! -
好文章,支持老大!
------------------------------------
我的Drupal小站:www.boygj.com
Drupal小站:http://boygj.com/
不錯,有空試一試吧.
不錯,有空試一試吧.
---------------------------------------------
網絡賺錢訊息
http://www.MakeMoneyOK.com
---------------------------------------------
關注瀏覽器資訊,Blog、討論區.......
http://www.PlzOn.com
很好~
Copyright 那一栏是 fieldgroup 吧
对的.. CCK构建的
对的..
CCK构建的
布拉格公园
还是不会改,第一步
还是不会改,第一步修改就出错。我是在官方默认主题下修改的。
加入如下代码就出错:
function _phptemplate_variables($hook, $variables) {
// loead the regions only for full views
if($hook == 'node' && !$vars['teaser']) {
//load region content assigned via blocks
foreach(array('node_inner_right') as $region) {
$variables[$region] = theme('blocks', $region);
}
foreach(array('node_inner_bottom') as $region) {
$variables[$region] = theme('blocks', $region);
}
}
return $variables;
}
------------------------------------
我的Drupal小站:www.boygj.com
Drupal小站:http://boygj.com/
bug.sorry~
bug.sorry~
怎么了?? -------------
怎么了??
---------------------------------------------------
http://Evance.name
布拉格公园
在默认模板下不能修
在默认模板下不能修改成功,不知道为什么?-__-
------------------------------------
我的Drupal小站:www.boygj.com
Drupal小站:http://boygj.com/
官方默认garland主题下
官方默认garland主题下的 template.php代码是这样的,根据Evance的修改要改成怎样样的才行。不懂PHP真难搞
<?php
// $Id: template.php,v 1.4.2.1 2007/04/18 03:38:59 drumm Exp $
/**
* Sets the body-tag class attribute.
*
* Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
*/
function phptemplate_body_class($sidebar_left, $sidebar_right) {
if ($sidebar_left != '' && $sidebar_right != '') {
$class = 'sidebars';
}
else {
if ($sidebar_left != '') {
$class = 'sidebar-left';
}
if ($sidebar_right != '') {
$class = 'sidebar-right';
}
}
if (isset($class)) {
print ' class="'. $class .'"';
}
}
/**
* Return a themed breadcrumb trail.
*
* @param $breadcrumb
* An array containing the breadcrumb links.
* @return a string containing the breadcrumb output.
*/
function phptemplate_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
return ''. implode(' › ', $breadcrumb) .'';
}
}
/**
* Allow themable wrapping of all comments.
*/
function phptemplate_comment_wrapper($content, $type = null) {
static $node_type;
if (isset($type)) $node_type = $type;
if (!$content || $node_type == 'forum') {
return ''. $content . '';
}
else {
return ''. t('Comments') .''. $content .'';
}
}
/**
* Override or insert PHPTemplate variables into the templates.
*/
function _phptemplate_variables($hook, $vars) {
if ($hook == 'page') {
if ($secondary = menu_secondary_local_tasks()) {
$output = '';
$output .= "
\n". $secondary ."
\n";
$vars['tabs2'] = $output;
}
// Hook into color.module
if (module_exists('color')) {
_color_page_alter($vars);
}
return $vars;
}
return array();
}
/**
* Returns the rendered local tasks. The default implementation renders
* them as tabs.
*
* @ingroup themeable
*/
function phptemplate_menu_local_tasks() {
$output = '';
if ($primary = menu_primary_local_tasks()) {
$output .= "
\n". $primary ."
\n";
}
return $output;
}
------------------------------------
我的Drupal小站:www.boygj.com
Drupal小站:http://boygj.com/
同样试了一下,不是很好用
同样是了一下,不是很好用。。。 系统报错。
找到个文件 也许可以,
http://www.alldrupalthemes.com/blog/automagically-placing-adsense-inside-content.html
template.php的开头结尾。
貌似template.php文件的建立开头要有<?php,却不需要结束符号。
alexa check
A great alexa rating tool
php的设置就是这样,
php的设置就是这样,手册上有的。
注意: 文件末尾的 PHP 代码段结束标记可以不要,有些情况下当使用 include() 或者 require() 时省略掉会更好些,这样不期望的白空格就不会出现在文件末尾,之后仍然可以输出响应标头。在使用输出缓冲时也很便利,就不会看到由包含文件生成的不期望的白空格。
------
瞅瞅
------
Blog
regions和block有啥区别
请大家帮我说说,regions和block有啥区别呀。
谢谢
block是放在regions里的 #
block是放在regions里的
########## AD ################
http://www.petkk.com
最近新开的drupal6.x的子站,主要以学习为主,欢迎大家来交流
http://code.petkk.com
########## AD ################
主要以学习为主,欢迎大家来交流
http://playts.com