Перепишите вывод страницы терминов таксономии() без взлома ядра
В Drupal 7, taxonomy.pages.inc содержит taxonomy_term_page()
, который помещает <div class="term-listing-heading">
вокруг вывода заголовка таксономии.
Как я могу переписать вывод taxonomy_term_page() в моей теме, чтобы я мог удалить DIV без взлома ядра?
Я очень удивлен, что нет tpl.php файл доступен для taxonomy_term_page()
, так как это значительно упростит тематизацию.
3 answers
Вы можете сделать это с помощью страницы предварительной обработки примерно так:
function themename_preprocess_page(&$vars) {
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
unset($vars['page']['content']['system_main']['term_heading']['#prefix']);
unset($vars['page']['content']['system_main']['term_heading']['#suffix']);
}
}
В вашей теме template.php
Я полагаю, что system_main
можно назвать как-то иначе, в зависимости от настроек вашего сайта.
Поскольку это обратный вызов меню, вы можете реализовать функцию hook_menu_alter() в модуле, чтобы изменить обратный вызов меню, вызываемый для этой страницы.
function mymodule_menu_alter(&$items) {
if (!empty($items['taxonomy/term/%taxonomy_term'])) {
$items['taxonomy/term/%taxonomy_term']['page callback'] = 'mymodule_term_page';
}
}
function mymodule_term_page($term) {
// Build breadcrumb based on the hierarchy of the term.
$current = (object) array(
'tid' => $term->tid,
);
$breadcrumb = array();
while ($parents = taxonomy_get_parents($current->tid)) {
$current = array_shift($parents);
$breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
}
$breadcrumb[] = l(t('Home'), NULL);
$breadcrumb = array_reverse($breadcrumb);
drupal_set_breadcrumb($breadcrumb);
drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name);
$build = array();
$build['term_heading'] = array(
'term' => taxonomy_term_view($term, 'full'),
);
if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10))) {
$nodes = node_load_multiple($nids);
$build += node_view_multiple($nodes);
$build['pager'] = array(
'#theme' => 'pager',
'#weight' => 5,
);
}
else {
$build['no_content'] = array(
'#prefix' => '<p>',
'#markup' => t('There is currently no content classified with this term.'),
'#suffix' => '</p>',
);
}
return $build;
}
Как и в предыдущем примере, за исключением того, что может быть более чистым и более надежным в будущем изменять результаты из taxonomy_term_page в оболочке, а не копировать исходную функцию оптом:
function mymodule_menu_alter(&$items) {
if (!empty($items['taxonomy/term/%taxonomy_term'])) {
$items['taxonomy/term/%taxonomy_term']['page callback'] = '_custom_taxonomy_term_page';
}
}
function _custom_taxonomy_term_page ( $term ) {
$build = taxonomy_term_page( $term );
// Make customizations then return
unset( $build['term_heading']['#prefix'] );
unset( $build['term_heading']['#suffix'] );
return $build;
}