欢迎各位兄弟 发布技术文章
这里的技术是共享的
我做的drupal6的例子
//自定义的主题
function shipingzhongcustom_init() {
global $user, $custom_theme;
// Set all node pages (including the node itself, as well as pages for
// editing it, deleting it, etc.) to default to using the 'some_theme'
// theme, rather than the site's normal default theme.
if(arg(0) == 'user'){
$custom_theme = 'garland';
}
}
Drupal 6.x:
<?php
/**
* Implements hook_init().
*/
function mymodule_init() {
global $user, $custom_theme;
// Set all node pages (including the node itself, as well as pages for
// editing it, deleting it, etc.) to default to using the 'some_theme'
// theme, rather than the site's normal default theme.
if (arg(0) == 'node' && is_numeric(arg(1))) {
$custom_theme = 'some_theme';
// However, for editing page nodes, use the 'some_other_theme' theme
// instead.
if (arg(2) == 'edit' && ($node = node_load(arg(1))) && $node->type == 'page') {
$custom_theme = 'some_other_theme';
}
}
// If the current user has a special role assigned to them, display all
// pages of the site (including those listed above) using the 'special_theme'
// theme.
if (in_array(variable_get('mymodule_special_role', 0), array_keys($user->roles))) {
$custom_theme = 'special_theme';
}
}
?>
Drupal 7.x:
<?php
/**
* Implements hook_menu_alter().
*/
function mymodule_menu_alter(&$items) {
// Set the theme callback function for all node pages. As per the
// standard behavior for hook_menu() properties, this will be
// inherited by all paths underneath node/%node as well, unless
// they define their own theme callback.
$items['node/%node']['theme callback'] = 'mymodule_default_node_theme';
// Set a different theme callback for node edit pages, and pass
// along the node object to this function so we can make decisions
// based on it.
$items['node/%node/edit']['theme callback'] = 'mymodule_edit_node_theme';
$items['node/%node/edit']['theme arguments'] = array(1);
}
/**
* Defaults to using the 'some_theme' theme for node pages.
*/
function mymodule_default_node_theme() {
return 'some_theme';
}
/**
* For editing page nodes, uses the 'some_other_theme' theme.
*/
function mymodule_edit_node_theme($node) {
return $node->type == 'page' ? 'some_other_theme' : mymodule_default_node_theme();
}
/**
* Implements hook_custom_theme().
*/
function mymodule_custom_theme() {
global $user;
// If the current user has a special role assigned to them, then display all
// pages of the site (including those listed above) using the 'special_theme'
// theme.
if (in_array(variable_get('mymodule_special_role', 0), array_keys($user->roles))) {
return 'special_theme';
}
}
?>
来自 https://drupal.org/node/224333#custom_theme