首页 / 帖子
Drupal里面如何根据url的query切换一个主题?

比如 我设置一下 http://www.example.com?a=1 就用一个主题 a=2就用另一个主题,如何实现?

谢谢!

3个答案
YOYO
发布于:2015-03-13 14:46
  if (isset($_GET['theme']) &&  is_string($_GET['theme'])) {
    global $custom_theme;
    $custom_theme = $_GET['theme'];
  }

把上面的代码加到hook_init里面试试,代码稍微做调整一下!

发布于:2015-03-13 14:57

试过这个模块 ThemeKey 吗?里面可以配置很多规则,包括 Drupal: $_GET['q'] - Current value of Drupal's query parameter "q"

YOYO
发布于:2015-03-26 11:46

这个推荐写在Hook_custom_theme

/**
 * Implements hook_custom_theme().
 */
function mymoduleglobal_custom_theme() {

  if (user_is_admin()) {

    return 'seven';

  }

  else {

    return 'mycustomadmin_theme';

  }
}