TODO: To change the header's content go to Dr.Explain menu Options : Project Settings : HTML (CHM) Export : Setup HTML Template and Layout
×
Menu
Index

NHP theme options

 
Có một thư viện giúp bạn tạo theme options nhanh chóng điển hình là NHP Theme Options.
Download tại: https://github.com/leemason/NHP-Theme-Options-Framework
 
 
1. Nhúng thư viện:
if(!class_exists('NHP_Options')){
     require_once( dirname( __FILE__ ) . '/lib/nhp/options/options.php' );
}
 
2. Tạo trường settings:
Thư viện có file mẫu tạo đầy đủ các trường, bạn có thể tham khảo trong file nhp-options.php
Tham khảo ví dụ này:
add_action('init', 'admin');
function admin(){
          $args = array();
 
          $args['share_icons']['twitter'] = array(
               'link' => 'http://twitter.com/parisholley',
               'title' => 'Folow me on Twitter',
               'img' => NHP_OPTIONS_URL.'img/glyphicons/glyphicons_322_twitter.png'
          );
 
          $args['share_icons']['linked_in'] = array(
               'link' => 'http://www.linkedin.com/in/parisholley',
               'title' => 'Find me on LinkedIn',
               'img' => NHP_OPTIONS_URL.'img/glyphicons/glyphicons_337_linked_in.png'
          );
 
          $args['opt_name'] = 'asyncjs';    #this is option name call by get_option('asyncjs  ')
          $args['menu_title'] = 'Async JS';
          $args['page_title'] = 'Asynchronous Javascript';
          $args['page_slug'] = 'asyncjs';
          $args['show_import_export'] = false;
          $args['page_position'] = 102419882;
          $args['dev_mode'] = false;
 
          $sections = array(array(
               'icon' => NHP_OPTIONS_URL.'img/glyphicons/glyphicons_280_settings.png',
               'title' => 'Settings',
               'fields' => array(
                    'exclude_name' => array(
                         'id' => 'exclude_name',
                         'type' => 'textarea',
                         'title' => 'Exclude by Name',
                         'desc' => 'Enter a comma delimited list (ie: "jquery,jqueryui").',
                         'sub_desc' => 'The name is the key used to queue the javascript file within wordpress.'
                    ),
                    'exclude_js' => array(
                         'id' => 'exclude_js',
                         'type' => 'textarea',
                         'title' => 'Exclude by File',
                         'desc' => 'Enter a comma delimited list (ie: "file1.js,file2.js").',
                         'sub_desc' => 'If you do not know the script key, you exclude based on the file name.'
                    ),
                    'head_file' => array(
                         'id' => 'head_file',
                         'type' => 'text',
                         'title' => 'Select Head.js File',
                         'desc' => 'Enter the filename of the head.js file in the js folder.',
                         'sub_desc' => 'This is an advanced setting, leave it as default if you are unsure of what it does.',
                         'std' => 'default xx'
                    ),
                    'always_on' => array(
                         'id' => 'always_on',
                         'type' => 'checkbox',
                         'title' => 'Always include head.js file',
                         'desc' => 'Do you want to always include the head.js file in your head section even if there are no js files to output?',
                         'sub_desc' => 'This is useful if you\'re using some of the other features of head.js',
                    )
               )
          ));
 
          new NHP_Options($sections, $args);
     }
 
Tạo trường select đa lựa chọn.
<?php
array(
    'id' => '1', //must be unique
    'type' => 'multi_select', //the field type
    'title' => __('Multi Select Option', 'nhp-opts'),
    'sub_desc' => __('This is a little space under the Field Title in the Options table', 'nhp-opts'),
    'desc' => __('This is the description field, again good for additional info.', 'nhp-opts'),
    'options' => array('1' => __('Option 1', 'nhp-opts'), '2' => __('Option 2', 'nhp-opts')),// You must provide a set of key => value pairs
    'std' => array('1', '2')//this should be the key as defined above
    )
?>
 
 
3. Sử dụng:
- Lấy giá trị trường.
//get group options named 'asyncjs'
$options = get_option('asyncjs');
$options['head_file'];
$options['always_on'];
...
 
 
Made with help of Dr.Explain

Unregistered version