简体   繁体   中英

Drupal 7: add new option to theme configuration

So I have created a subtheme witch his parent is Drupal Bootstrap theme. I would like to add an option to share a second logo in the page (I have googled but I have found nothing).

在此处输入图片说明

As you see in the image, I would like to add the option just where the red line is between "logotip" and "Nom del lloc" and create a variable to acces to the second logo like $second_logo.

Is there a way to do this?

  • go to your theme
  • create new file theme-setting.php
  • implement the below hook " 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'), ); } 

I'll edit my answer again, to let you know a complete example to upload a second logo, because it is the proper way to do it Create this file in your custom theme:

theme-settings.php

Use customthemename_form_system_theme_settings_alter(&$form, $form_state) hook

For example:

 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'),

    );

Add the variable to youcustomtheme.info file, like this:

settings[second_logo] = ''

Finally, just you can do this in your /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;

That's it.

Please refer to the documentation: Theme settings D7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM