Aller au contenu principal
  • Facebook
  • Tweet
  • Plus Share
Accueil
  • Accueil
  • A propos
  • Portfolio
  • Experience
  • Blog
  • Contact

Blog

Rops Online

Par jbfelix | 31st Mars 2014

Ventes aux enchères sur https://www.rops-online.be

+

Dernière réalisation

Par jbfelix | 31st Mars 2014

www.lodewijkdevadder.net
+

D7: Adding custom settings / select options list to your theme

Par jbfelix | 31st Mars 2014

How to add this select list options to your D7 theme and display the selected option in PHP :

 

Result:

top --> Menu position = 0

right -->  Menu position = 1

 


  • Create a file called theme-settings.php in YOURTHEME's root directory

  • Add the select list in theme-settings.php 
<?php
function YOURTHEME_form_system_theme_settings_alter(&$form, $form_state) {
$form['YOURTHEME_menuposition'] = array(
'#type' => 'select',
'#title' => t('Menu Position'),
'#options' => array(
  0 => t('top'),
  1 => t('right'),
),
'#default_value' => theme_get_setting('YOURTHEME_menuposition'),
'#description' => t('Choose menu position.'),
);
}
?>
  • Flush cache
drush cc all
  • OPTION: define this setting in YOURTHEME.info file 
;;;;;;;;;;;;;;;;;;;;;
;; Settings
;;;;;;;;;;;;;;;;;;;;;
settings[YOURTHEME_menuposition] = 0
  • Display or use the result in a template file 
<?php print theme_get_setting('YOURTHEME_menuposition'); ?>
  • EXAMPLE: add a class "menutop" or "menuright" to the <body> tag.
    • edit template.php and add this function
<?php

/**
 * @file
 * template.php
 */
 function YOURTHEME_preprocess_html(&$variables) {
  switch (theme_get_setting('YOURTHEME_menuposition')) {
    case '0':
      $variables['classes_array'][] = 'menutop';
      break;

    case '1':
      $variables['classes_array'][] = 'menuright';
      break;
  }
}
  • Flush cache 
drush cc all
  • Smile !

WTFPL

+
  • 1
  • 2
  • 3
  • suivant ›
  • dernier »

DERNIERS BILLETS

Rops Online

Ventes aux enchères sur https://www.rops

Dernière réalisation
www.lodewijkdevadder.net
D7: Adding custom settings / select options list to your theme

How to add this select list options to your D7 theme and display the se

         

© Copyright 2014. jbfelix.be & Moove.be / Rue fonds de Wartet, 2 - 5024 Marche-les-Dames (Namur) / +32 (0)477/77.24.35 / jbfelix@gmail.com