添加regions到node.tpl.php由 Evance 于 周四, 2008-01-31 11:37 提交。
作者:Evance | 源文: Add some regions to node.tpl.php for drupal 但是要说明的是,上面的方法不适应于添加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里相应的位置。 <?php增加显示node_inner_right的代码: <?php if ($node_inner_right && $page !=0) { ?> 至于是把regions放到$content前还是后,css怎么写,这个又是另外一个范畴了。本文介绍的仅仅是如何添加一个regions到node.tpl.php里面。
|
用户登录导航水滴榜
新的论坛主题最新评论
新进会员
|
好文章,支持老大! -
好文章,支持老大!
------------------------------------
我的Drupal小站:www.boygj.com
不錯,有空試一試吧.
不錯,有空試一試吧.
---------------------------------------------
網絡賺錢訊息
http://www.MakeMoneyOK.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
bug.sorry~
bug.sorry~
怎么了?? -------------
怎么了??
---------------------------------------------------
http://Evance.name
在默认模板下不能修
在默认模板下不能修改成功,不知道为什么?-__-
------------------------------------
我的Drupal小站:www.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