如何从面包屑中删除 HOME

发布于 2024-09-16 19:21:12 字数 174 浏览 0 评论 0原文

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

例如:

$breadcrumb= PRODUCTS // SOFTWARE // FEATURES

而不是

HOME // PRODUCTS // SOFTWARE // FEATURES

I am using Drupal 6.17 and want to get rid of "HOME" in the breadcrumb output...

eg:

$breadcrumb= PRODUCTS // SOFTWARE // FEATURES

instead of

HOME // PRODUCTS // SOFTWARE // FEATURES

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

罪歌 2024-09-23 19:21:12

这是 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;
  }
}

Here's a Drupal 7 version:

/**
 * 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;
  }
}
风情万种。 2024-09-23 19:21:12

覆盖主题 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>';
  }
}

Override the breadcrumb in your theme's template.php file:

/**
 * 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>';
  }
}
深居我梦 2024-09-23 19:21:12

隐藏 Drupal 8 的“主页”面包屑

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


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

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

/**
 * 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 Configuration Syncing 与 Drupal 8,您还应该在同步目录中添加/修改 yourtheme.settings.yml 文件,然后运行drush cimsync


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

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

< img src="https://i.sstatic.net/CCocc.png" alt="演示更细致的主题设置的屏幕截图,其中包含 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 8 同步的 Drupal 配置,您应该还要添加/修改同步目录中的 yourtheme.settings.yml 文件,然后运行 ​​drush cimsync

Hide 'Home' Breadcrumb for Drupal 8

(Replace yourtheme with your theme's actual machine name...)


Option 1: fast and simple theme preprocess

Add the following to your theme's yourtheme.theme file:

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

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

Or Option 2: a checkbox option in theme settings

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

Add the following to your theme's 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'),
  );

}

Add the following to your theme's yourtheme.theme file:

/**
 * 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']);
  }
}

If you want the Home button to be disabled by default when the theme is installed, add the following to your theme's yourtheme.settings.yml:

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

If you're working with an existing site, and are using Drupal Configuration Syncing with Drupal 8, you should also add/modify the yourtheme.settings.yml file in the sync directory, and run drush cim sync.


Or Option 3: a more nuanced theme setting

In some cases, a site design might call for hiding the Home link if it is the only item in the breadcrumb trail, and when there are other items in the breadcrumb trail to leave Home in the breadcrumb trail.

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

Here's how to implement the radio buttons depicted above:

Add the following to your theme's 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'),
  );

}

Add the following to your theme's yourtheme.theme file:

/**
 * 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']);
  }
}

If you want the Home button to be disabled by default when the theme is installed, add the following to your theme's yourtheme.settings.yml:

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

If you're working with an existing site, and are using Drupal Configuration Syncing with Drupal 8, you should also add/modify the yourtheme.settings.yml file in the sync directory, and run drush cim sync.

困倦 2024-09-23 19:21:12

在 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;
            } 
}

In templated.php ask if "Home page" and be language specific. Take out ( && $language_url->languag**e and **global $language_url;) if you don't need language look up. Also change "/htdocs/drupal/de" in "href" to appropriate 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;
            } 
}
春风十里 2024-09-23 19:21:12

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

If you have path breadcrumbs module installed. Go to structure > Path breadcrumbs > path breadcrumbs settings, then check the "Hide breadcrumbs navigation for single breadcrumb", save configuration, refresh page. Done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文