10

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

例如:

$breadcrumb= 产品 // 软件 // 功能

代替

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

4

6 回答 6

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;
  }
}
于 2012-02-15T15:45:03.253 回答
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>';
  }
}
于 2010-08-26T22:09:32.697 回答
3

隐藏 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:主题设置中的复选框选项

演示 Drupal 管理员外观 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​​.


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

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

屏幕截图展示了一个更细致入微的主题设置,其中包含 3 个单选按钮选项来选择主页面包屑可见性选项

以下是实现上述单选按钮的方法:

将以下内容添加到您的主题中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​​.

于 2018-01-25T02:13:33.203 回答
1

主题化面包屑输出 HTML
自定义面包屑

于 2010-08-26T21:51:04.360 回答
0

在 templated.php 中询问“主页”是否为特定语言。如果您不需要语言查找,请取出(&& $language_url->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;
            } 
}
于 2013-03-07T01:51:39.013 回答
0

如果您安装了路径面包屑模块​​。转到结构>路径面包屑>路径面包屑设置,然后选中“隐藏单个面包屑的面包屑导航”,保存配置,刷新页面。完毕。

于 2013-09-25T11:28:21.727 回答