如何从面包屑中删除HOME

时间:2010-08-26 21:37:05

标签: drupal drupal-6 breadcrumbs

我正在使用Drupal 6.17并希望摆脱面包屑输出中的“HOME”...

例如:

$ breadcrumb = PRODUCTS // SOFTWARE // FEATURES

而不是

主页//产品//软件//功能

6 个答案:

答案 0 :(得分:7)

这是一个Drupal 7版本:

/**
 * Get rid of Home in breadcrumb trail.
 */
function <themename>_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];

  if (!empty($breadcrumb)) {
    // Provide a navigational heading to give context for breadcrumb links to
    // screen-reader users. Make the heading invisible with .element-invisible.
    $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';

    array_shift($breadcrumb); // Removes the Home item
    $output .= '<div class="breadcrumb">' . implode(' » ', $breadcrumb) . '</div>';
    return $output;
  }
}

答案 1 :(得分:5)

覆盖主题的template.php文件中的痕迹:

/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return a string containing the breadcrumb output.
 */
function phptemplate_breadcrumb($breadcrumb) {
  if (!empty($breadcrumb)) {
    array_shift($breadcrumb); // Removes the Home item
    return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
  }
}

答案 2 :(得分:1)

答案 3 :(得分:0)

在templated.php中询问“主页”是否属于特定语言。如果您不需要语言查找,请取出(&amp;&amp; $ language_url-&gt; languag ** e和** global $ language_url; )。同时将“href”中的“/ htdocs / drupal / de”更改为适当的URL。

function _YOUR_THEME_NAME_breadcrumb(&$variables) {
    $breadcrumb = $variables['breadcrumb'];
    global $language_url;

          if (drupal_is_front_page()){
              return;
              } elseif(!empty($breadcrumb) && $language_url->language == 'de') {
              $breadcrumb[0] = '<a href="/htdocs/drupal/de">STARTSEITE</a>';
                $breadcrumb = implode(' | ', $breadcrumb);
                return $breadcrumb;
            } 
}

答案 4 :(得分:0)

如果您安装了路径breadcrumbs模块。转到结构&gt;路径面包屑&gt; path breadcrumbs设置,然后选中“隐藏面包屑导航为单个痕迹”,保存配置,刷新页面。完成。

答案 5 :(得分:0)

为Drupal 8隐藏'主页'面包屑

(将yourtheme替换为您主题的实际机器名称...)

选项1:快速简单的主题预处理

将以下内容添加到主题的yourtheme.theme文件中:

/**
 * Prepares variables for `breadcrumb.html.twig`.
 */
function yourtheme_preprocess_breadcrumb(&$variables){

  // Remove 'Home' from breadcrumb trail.
  if (count($variables['breadcrumb'])) {
    array_shift($variables['breadcrumb']);
  }
}

或选项2:主题设置中的复选框选项

Screenshot demonstrating what the theme settings option looks like in the Drupal Admin Appearance UI

将以下内容添加到主题theme-settings.php

<?php

/**
 * Implements hook_form_system_theme_settings_alter().
 */
function yourtheme_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id = NULL) {

  $form['theme_settings']['hide_home_breadcrumb'] = array(
    '#type'          => 'checkbox',
    '#title'         => t('Hide <em>Home</em> in breadcrumb trail'),
    '#default_value' => theme_get_setting('hide_home_breadcrumb', 'yourtheme'),
  );

}

将以下内容添加到主题的yourtheme.theme文件中:

/**
 * Prepares variables for `breadcrumb.html.twig`.
 */
function yourtheme_preprocess_breadcrumb(&$variables){

  // Remove 'Home' from breadcrumb trail.
  if (!empty(theme_get_setting('hide_home_breadcrumb', 'yourtheme')) && count($variables['breadcrumb'])) {
    array_shift($variables['breadcrumb']);
  }
}

如果您希望在安装主题时默认禁用“主页”按钮,请将以下内容添加到主题yourtheme.settings.yml

# Hide 'Home' in breadcrumb trail by default.
hide_home_breadcrumb: 1

如果您正在使用现有网站,并且正在使用Drupal配置同步和Drupal 8,您还应该在同步目录中添加/修改yourtheme.settings.yml文件,然后运行drush cim sync。< / p>

或选项3:更细微的主题设置

在某些情况下,网站设计可能会要求隐藏 Home 链接(如果它是痕迹路径中的唯一项目),当面包屑路径中有其他项目要离开时在痕迹路径中 Home

Screenshot demonstrating a more nuanced theme setting with 3 radio button options to select home breadcrumb visibility options

以下是如何实现上述单选按钮:

将以下内容添加到主题theme-settings.php

<?php

/**
 * Implements hook_form_system_theme_settings_alter().
 */
function yourtheme_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id = NULL) {

  $form['breadcrumbs'] = [
    '#type' => 'details',
    '#title' => t('Breadcrumb'),
    '#open' => TRUE,
  ];

  $form['breadcrumbs']['hide_home_breadcrumb'] = array(
    '#type' => 'radios',
    '#options' => [
      '0' => 'Show <em>Home</em> in breadcrumb trail (Drupal’s default behavior)',
      '1' => 'Remove <em>Home</em> from breadcrumb trail',
      '2' => 'Remove <em>Home</em> when it is the only breadcrumb in trail',
    ],
    '#default_value' => theme_get_setting('hide_home_breadcrumb', 'yourtheme'),
  );

}

将以下内容添加到主题的yourtheme.theme文件中:

/**
 * Prepares variables for `breadcrumb.html.twig`.
 */
function yourtheme_preprocess_breadcrumb(&$variables){

  // Remove 'Home' from breadcrumb trail based on theme settings variable.
  //
  // Possible values:
  // - 0: do not remove
  // - 1: remove
  // - 2: remove if its the only item
  $hide_home_breadcrumb = theme_get_setting('hide_home_breadcrumb', 'yourtheme');
  if ($hide_home_breadcrumb == '1' && count($variables['breadcrumb'])) {
    array_shift($variables['breadcrumb']);
  }
  elseif ($hide_home_breadcrumb == '2' && count($variables['breadcrumb']) == 1) {
    array_shift($variables['breadcrumb']);
  }
}

如果您希望在安装主题时默认禁用“主页”按钮,请将以下内容添加到主题yourtheme.settings.yml

# Remove 'Home' in breadcrumb trail if its the only item.
hide_home_breadcrumb: '2'

如果您正在使用现有网站,并且正在使用Drupal配置同步和Drupal 8,您还应该在同步目录中添加/修改yourtheme.settings.yml文件,然后运行drush cim sync。< / p>