Option tree
How to Use Option Tree Theme Option
We describing option tree from previous tune, here describe option tree theme option uses. If you want only the theme option, every time must need to configure option tree like previous tune. Theme option is a very important for control a theme function.
Taking all all below code taken in you theme-option.php file in inc folder. Here we are taking single code from option tree demo-theme-option.php
<?php /** * Initialize the options before anything else. */ add_action( 'admin_init', '_custom_theme_options', 1 ); /** * Theme Mode demo code of all the available option types. * * @return void * * @access private * @since 2.0 */ function _custom_theme_options() { /** * Get a copy of the saved settings array. */ $saved_settings = get_option( 'option_tree_settings', array() ); /** * Create a custom settings array that we pass to * the OptionTree Settings API Class. */ $custom_settings = array( 'contextual_help' => array( 'content' => array( array( 'id' => 'general_help', 'title' => 'General', 'content' => '<p>Help content goes here!</p>' ) ), 'sidebar' => '<p>Sidebar content goes here!</p>' ), 'sections' => array( array( 'title' => 'Social Links ', 'id' => 'social_links' ) ), 'settings' => array( array( 'label' => 'Facebook Link', 'id' => 'facebook', 'type' => 'text', 'desc' => 'Enter your facebook URL.', 'section' => 'social_links' ) ) ); /* allow settings to be filtered before saving */ $custom_settings = apply_filters( 'option_tree_settings_args', $custom_settings ); /* settings are not the same update the DB */ if ( $saved_settings !== $custom_settings ) { update_option( 'option_tree_settings', $custom_settings ); } }
If you deeply see this theme-option.php code ‘contextual_help’ , ‘sections’ & ‘settings’ which are shown in image.
If you taking more array on each ‘contextual_help’ , ‘sections’ & ‘settings’ by changing ID there get more section show in dashboard.
Now describe how to use in theme
If your HTML like this:
<div class="social span8"> <a class="facebook" href="#"></a> </div>
This HTML will be like this when use theme option.
<div class="social span8"> <?php $facebook_link = get_option_tree( 'facebook', '', false ); //here facebook same as theme-option.php setting array ID ?> <?php if($facebook_link) : ?> <a class="facebook" href="<?php echo $facebook_link; ?>"></a> <?php endif; ?> </div>
Here explain one example, like that you can use every where. If you any problem to use option tree theme option comment here.
Comments are closed