2012-03-23 21 views
0

我正在構建一個Drupal站點,它有4個不同的主題與不同的主題模板。Drupal 7主題切換和內容相關

我需要使用相同的Drupal數據庫來控制所有4個主題的所有內容。

我爲每個主題設置了分類,所以當我創建內容時,我可以將它應用於四種不同的主題之一。

的URL必須看起來像

mysite.com/theme1/node/21

而且

mysite.com/theme2/node/2

此外,我需要請確保

mysite.com/theme1需要根據URL提供該主題的page-front.tpl.php

我試過使用的主題鍵工作正常,除非我不知道如何只拉取具有該網站的應用分類術語的內容。

,我不能讓它像這樣的東西

mysite.com/theme2/node/1

工作僅限於

mysite.com/node/1/theme2

任何想法,或任何你可以提供給我指向正確的方向將不勝感激。

回答

1

有可能有很多方法可以做到這一點,但這是我該怎麼做的。

  • 創建一個視圖顯示,其參數根據從名稱翻譯到tid的taxnonomy項進行過濾。這個視圖將作爲首頁。
  • 還創建一個視圖顯示,它帶有兩個參數,檢查第二個參數是否是使用第一個參數分類術語名稱標記的節點。如果它沒有找到沒有返回。
  • 請注意,我們只會在代碼中訪問這些視圖,因此如果它們是頁面或塊,則無關緊要。確保不要將它們命名爲主題(如果它們是頁面),那麼它們將覆蓋我們的菜單條目。

你也可以像在node.module中那樣查詢東西,但是我個人更喜歡使用視圖來完成過濾。如果你不熟悉在example_menu()函數中傳遞給views_embed_view()的參數,你可以找到它的documentation here

這段代碼中可能存在拼寫錯誤,但沒有我現在可以看到的東西。 好資源:http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7

/** 
* Implements hook_menu(). 
* 
* Here we define the new frontpages as well as a node view page for all them custom themes. 
*/ 
function example_menu() { 
    $items = array(); 
    foreach (example_custom_themes() as $theme) { 
    // Define the front page 
    $items[$theme] = array(
     'page callback' => 'views_embed_view', 
     'page arguments' => array('VIEW', 'DISPLAY', $theme), // The front page view 
     'access arguments' => array('access content'), 
     'type' => MENU_CALLBACK, 
     'theme callback' => 'example_theme_callback', 
     'theme arguments' => array($theme), 
    ); 
    // Define the node views 
    $items[$theme . '/node/%node'] = array(
     'title callback' => 'node_page_title', 
     'title arguments' => array(1), 
     'page callback' => 'views_embed_view', 
     'page arguments' => array('VIEW', 'DISPLAY', $theme, 1), // The node view display 
     'access callback' => 'node_access', 
     'access arguments' => array('view', 1), 
     'theme callback' => 'example_theme_callback', 
     'theme arguments' => array($theme), 
    ); 
    } 
    return $items; 
} 

/** 
* Returns an array of the machine named custom themes. 
*/ 
function example_custom_themes() { 
    return array('theme1', 'theme2'); 
} 

/** 
* Does nothing but return the theme name 
*/ 
function example_theme_callback($theme) { 
    return $theme; 
} 

/** 
* Check if the url matches the front page of a theme. If so, suggest front template. 
*/ 
function example_preprocess_page(&$variables) { 
    if (in_array(arg(0), example_custom_themes()) && is_null(arg(1))) { 
    $variables['theme_hook_suggestions'] = 'page__front'; 
    } 
}