有可能有很多方法可以做到這一點,但這是我該怎麼做的。
- 創建一個視圖顯示,其參數根據從名稱翻譯到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';
}
}
來源
2012-03-24 19:53:09
oxy