簡體   English   中英

Drupal 7:為主題配置添加新選項

[英]Drupal 7: add new option to theme configuration

所以我創建了一個子主題女巫,他的父母是Drupal Bootstrap主題。 我想添加一個選項來共享頁面中的第二個徽標(我已經用Google搜索,但是什么也沒找到)。

在此處輸入圖片說明

如您在圖像中看到的,我想在“ logotip”和“ Nom del lloc”之間的紅線之間添加選項,並創建一個變量來訪問第二個徽標,例如$ second_logo。

有沒有辦法做到這一點?

  • 去你的主題
  • 創建新文件theme-setting.php
  • 實現下面的鈎子“ hook_form_system_theme_settings_alter

     function <theme_name>_form_system_theme_settings_alter(&$form, &$form_state, $form_id = NULL) { //add your variable field $form['theme_settings']['second_logo'] = array( '#type' => 'checkbox', '#title' => t('Use the second logo'), '#default_value' => theme_get_setting('second_logo'), ); } 

我將再次編輯答案,以使您知道上傳第二個徽標的完整示例,因為這樣做是正確的方法,請按照您的自定義主題創建此文件:

theme-settings.php

使用customthemename_form_system_theme_settings_alter(&$ form,$ form_state)掛鈎

例如:

 function customthemename_form_system_theme_settings_alter(&$form, &$form_state, $form_id = NULL) {
        $form['second_logo'] = array(
        '#type' => 'checkbox',
        '#title' => t('Use the second logo'),
        '#default_value' => theme_get_setting('second_logo'),

    );

將變量添加到youcustomtheme.info文件,如下所示:

settings[second_logo] = ''

最后,只需在/sites/all/themes/customthemename/templates/html.tpl.php中執行以下操作:

 <?php
      if (theme_get_setting('second_logo')): ?>
          <img src="<?php echo path_to_theme();  ?>/images/your_logo" />
   <?php endif;

而已。

請參考文檔: 主題設置D7

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM