아마도 이렇게하는 데는 많은 방법이 있지만 이것이 내가하는 방법입니다.
- taxnonomy term을 필터링하여 name에서 tid로 변환되는 인수가있는보기 표시를 만듭니다. 이보기는 첫 페이지로 작동합니다.
- 또한 두 개의 인수가 첫 번째 인수 택 소노 미 term 이름으로 태그 지정된 노드인지 확인하는 두 개의 인수를 사용하는보기 표시를 작성하십시오. 그것이 반환되지 않으면.
- 코드에서 이러한보기에만 액세스하므로 페이지 또는 블록 인 경우 중요하지 않습니다. 그들이 페이지 인 경우 테마와 동일한 이름을 지정하지 마십시오. 그런 다음 메뉴 항목을 덮어 씁니다.
node.module과 마찬가지로 쿼리 할 수도 있지만 개인적으로 필자는 필터링을 수행하기 위해 뷰를 사용하는 것을 선호합니다. example_menu() 함수의 views_embed_view() 인수에 익숙하지 않은 경우 example_menu() 함수에서 찾을 수 있습니다. 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