[英]Drupal 7: add new option to theme configuration
實現下面的鈎子“ 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.