Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Download Option Tree: http://wordpress.org/extend/plugins/option-tree/
- Usage
- =======================
- /* 1. put option-tree folder in inc dolder
- 2. Then go to option-tree > assets > theme-mode > demo-theme-options.php and copy it,
- 3. paste it (demo-theme-options.php) in inc folder and rename in to theme-options.php
- 4. Call theme-options.php in functions.php like beelow code.
- 5. if you like to use meta box then call this file like this - include_once( 'inc/meta-boxes.php' );
- */
- functions.php
- Activate Option Tree
- add_filter( 'ot_show_pages', '__return_false' ); // if this under comment this is Documentation
- add_filter( 'ot_show_new_layout', '__return_false' );// this code for option panel css
- add_filter( 'ot_theme_mode', '__return_true' ); // this code for option panel css
- include_once( 'inc/option-tree/ot-loader.php' );
- include_once( 'inc/theme-options.php' );
- Create Option Tree In the theme
- ================================
- Creating Simple Option Tree In the theme: http://pastebin.com/auGpnWxP
- Get Data From Option Tree
- ==========================
- Condtional Data
- <?php if ( function_exists( 'get_option_tree') ) : if( get_option_tree( 'your_option_id_here') ) : ?>
- <?php get_option_tree( 'your_option_id_here', '', 'true' ); ?>
- <?php else : ?>
- Your Default Data
- <?php endif; endif; ?>
- Simple Data
- <?php get_option_tree( 'your_option_id_here', '', 'true' ); ?>
- <!-- Another use for give any name to custom post category -->
- <!-- use at frist create category in wp the put the same category name to theme option -->
- <?php
- $your_variable = get_option_tree( 'your_option_id_here', '', false );
- ?>
- <?php
- global $post;
- $args = array( 'posts_per_page' => 4, 'post_type'=> 'portfolio-items', 'portfolio_cat' =>
- $your_variable); // <!-- for call -->
- $myposts = get_posts( $args );
- foreach( $myposts as $post ) : setup_postdata($post); ?>
- <!-- content hare -->
- <?php endforeach; ?>
- Tutorial Link: http://rrfoundation.net/391
- <!-- Creating Simple Option Tree In the theme-->
- <?php
- add_action( 'admin_init', 'custom_theme_options', 1 );
- function custom_theme_options() {
- $saved_settings = get_option( 'option_tree_settings', array() );
- $custom_settings = array(
- // This sections
- 'sections' => array(
- array(
- 'id' => 'general',
- 'title' => 'Site Settings'
- )
- ),
- // This settings
- //1. This settings One
- 'settings' => array(
- array(
- 'id' => 'logo_text',
- 'label' => 'Logo Text',
- 'desc' => 'Use H1, H2, H3 tag',
- 'type' => 'textarea',
- 'section' => 'general'
- ),
- //1. This settings two
- array(
- 'id' => 'footer_text',
- 'label' => 'Footer Text',
- 'type' => 'textarea',
- 'section' => 'general'
- )
- )
- );
- if ( $saved_settings !== $custom_settings ) {
- update_option( 'option_tree_settings', $custom_settings );
- }
- }
- ?>
- // for meta box call same as custom fields call just change the id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement