回答:
Drupal 6ソリューション:
$custom_themeページ実行のかなり早い段階でグローバル変数を変更するようにします。
global $custom_theme;
$custom_theme = 'garland';$custom_theme定義されていますか?テーマを変更するのに十分ですか?
                    hook_custom_theme api.drupal.org/api/drupal/modules%21system%21system.api.php/…
                    プログラムでそれを行う方法を尋ねたのは知っていますが、それが実際の問題ではなく解決策である場合は、ThemeKeyモジュールを使用することもできます。これにより、条件を設定して、満たされたときにテーマを変更できます。パス、分類法、コンテンツタイプ、作成日または編集日などに基づいて条件を作成できます。Themekey Propertiesモジュールモジュールを追加して、さらに多くのオプションを取得することもできます。
繰り返しますが、これはプログラムではないことは知っていますが、あなたの質問の背後にある本当の質問が条件に基づいてテーマを変更する方法であるかどうかはわかりません。
drush vset theme_default garland
drush vset admin_theme garland
drush cc allデフォルトのテーマと管理テーマを変更する基本:
// Changes the theme to Garland
variable_set('theme_default', $theme_default);
// Changes the administration theme to Garland
variable_set('admin_theme', $admin_theme);以下に、BartikやGarland(Drupal 6および7でテスト済み)などのデフォルトのDrupalテーマにテーマを安全に戻す小さな関数を示します。
/**
 * Set the active Drupal themes (the default and the administration theme) to default ones.
 * Tested in Drupal 6, 7 (but possibly working in version 8 too according to the documentations [some similarities between 7 and 8]).
 */
function TESTMODULE_set_active_theme_to_default($affect_admin_theme = TRUE) {
  // Provides a list of currently available themes.
  $list_themes = list_themes(TRUE);
  // 6, 7, 8, etc.
  $major_version = (int)VERSION;
  $theme_default = isset($list_themes['bartik']) ? 'bartik' : 'garland';
  $admin_theme   = isset($list_themes['seven']) ? 'seven' : 'garland';
  // Changes the theme to Garland
  variable_set('theme_default', $theme_default);
  // Changes the administration theme to Garland if argument is TRUE
  if($affect_admin_theme){
    variable_set('admin_theme', $admin_theme);
  }
  // if Switchtheme module (https://drupal.org/project/switchtheme) is enabled, use it
  if (module_exists('switchtheme')) {
    if (empty($_GET['theme']) || $_GET['theme'] !== $theme_default) {
      $query = array(
        'theme' => $theme_default
      );
      // in D6, drupal_goto's second argument is the query string,
      // in >=D7, a more general $options array is used
      if($major_version < 7){
        $options = $query;
      }
      else{
        $options = array('query' => $query);
      }
      drupal_goto($_GET['q'], $options);
    }
  }
  drupal_set_message(t('Default theme has been changed to %theme_default, administration theme has been changed to %admin_theme.', array(
    '%theme_default' => $theme_default,
    '%admin_theme' => $admin_theme
  )));
}hook_init()実装で呼び出すことができます(不要になったらコメントアウトしてください):
/**
 * Implements hook_init()
 */
function TESTMODULE_init() {  
  // ATTENTION! Comment out the following line if it's not needed anymore!
  TESTMODULE_set_active_theme_to_default();
}variable_set('theme_default','yourtheme');
                    Drupal 7では、次を使用しますhook_custom_theme()。
/**
 * Implements hook_custom_theme()
 * Switch theme for a mobile browser
 * @return string The theme to use
 */
function mymodule_custom_theme()  {
    //dpm($_SERVER['HTTP_USER_AGENT']);
    $theme = 'bartik'; // core theme, used as fallback
    $themes_available = list_themes(); // get available themes
    if (preg_match("/Mobile|Android|BlackBerry|iPhone|Windows Phone/", $_SERVER['HTTP_USER_AGENT'])) {
        if (array_key_exists('custommobiletheme', $themes_available)) $theme = 'custommobiletheme';
        else { drupal_set_message("Unable to switch to mobile theme, because it is not installed.", 'warning'); }
    }
    else if (array_key_exists('nonmobiletheme', $themes_available)) $theme = 'nonmobiletheme';
    // else, fall back to bartik
    return $theme;
}<emoticode />からの適応
現在のページに使用するテーマの機械可読な名前を返します。
この関数のコメントは読む価値があります。
このフックを使用して、現在のページ要求のテーマを動的に設定できます。動的な条件に基づいてテーマをオーバーライドする必要があるモジュール(たとえば、現在のユーザーの役割に基づいてテーマを設定できるモジュール)で使用する必要があります。このフックの戻り値は、hook_menu()のテーマコールバック関数によって設定された有効なページごとまたはセクションごとのテーマを持つページを除くすべてのページで使用されます。それらのページのテーマは、hook_menu_alter()を使用してのみ上書きできます。
同じパスに対して異なるテーマを返すことは、ページキャッシングでは機能しない可能性があることに注意してください。これは、特定のパスの匿名ユーザーが異なる条件で異なるテーマを返す場合に問題になる可能性が最も高くなります。
一度に使用できるテーマは1つだけなので、このフックから有効なテーマ名を返す最後の(つまり、最も重みが高い)モジュールが優先されます。