Advertisement
arnabkumar

Option Tree

Apr 15th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.92 KB | None | 0 0
  1.  
  2.     <?php
  3.  
  4.     Download Option Tree: http://wordpress.org/extend/plugins/option-tree/
  5.      
  6.      
  7.      
  8.      
  9.     Usage
  10.      
  11.     =======================
  12.     /* 1. put option-tree folder in inc dolder
  13.    
  14.     2. Then go to option-tree > assets > theme-mode > demo-theme-options.php and copy it,
  15.    
  16.     3. paste it (demo-theme-options.php) in inc folder and rename in to theme-options.php
  17.    
  18.     4. Call theme-options.php in functions.php like beelow code.
  19.    
  20.     5. if you like to use meta box then call this file like this -  include_once( 'inc/meta-boxes.php' );
  21.    
  22.     */
  23.      
  24.      
  25.      
  26.     functions.php
  27.      
  28.      
  29.      
  30.     Activate Option Tree
  31.      
  32.    add_filter( 'ot_show_pages', '__return_false' ); // if this under comment this is Documentation
  33.      
  34.     add_filter( 'ot_show_new_layout', '__return_false' );// this code for option panel css
  35.      
  36.     add_filter( 'ot_theme_mode', '__return_true' ); // this code for option panel css
  37.      
  38.     include_once( 'inc/option-tree/ot-loader.php' );
  39.      
  40.     include_once( 'inc/theme-options.php' );
  41.      
  42.      
  43.      
  44.      
  45.      
  46.      
  47.      
  48.     Create Option Tree In the theme
  49.      
  50.     ================================
  51.      
  52.      
  53.      
  54.     Creating Simple Option Tree In the theme: http://pastebin.com/auGpnWxP
  55.      
  56.      
  57.      
  58.      
  59.      
  60.      
  61.     Get Data From Option Tree
  62.      
  63.     ==========================
  64.      
  65.      
  66.      
  67.     Condtional Data
  68.      
  69.     <?php if ( function_exists( 'get_option_tree') ) : if( get_option_tree( 'your_option_id_here') ) : ?>    
  70.      
  71.         <?php get_option_tree( 'your_option_id_here', '', 'true' ); ?>
  72.      
  73.     <?php else : ?>
  74.      
  75.         Your Default Data
  76.      
  77.     <?php endif; endif; ?>
  78.      
  79.      
  80.      
  81.     Simple Data
  82.      
  83.     <?php get_option_tree( 'your_option_id_here', '', 'true' ); ?>
  84.    
  85.    
  86.     <!-- Another use for give any name to custom post category -->
  87.     <!-- use at frist create category in wp the put the same category name to theme option -->
  88.    
  89.        
  90.         <?php
  91.             $your_variable = get_option_tree( 'your_option_id_here', '', false );
  92.         ?>         
  93.            
  94.            
  95.     <?php
  96.     global $post;
  97.     $args = array( 'posts_per_page' => 4, 'post_type'=> 'portfolio-items', 'portfolio_cat' =>
  98.     $your_variable); // <!-- for call -->
  99.     $myposts = get_posts( $args );
  100.     foreach( $myposts as $post ) : setup_postdata($post); ?>
  101.    
  102.     <!-- content hare -->
  103.  
  104.     <?php endforeach; ?>               
  105.  
  106.      
  107.      
  108.     Tutorial Link: http://rrfoundation.net/391
  109.    
  110.    
  111.     <!-- Creating Simple Option Tree In the theme-->
  112.        
  113.  
  114.     <?php
  115.      
  116.     add_action( 'admin_init', 'custom_theme_options', 1 );
  117.      
  118.     function custom_theme_options() {
  119.      
  120.       $saved_settings = get_option( 'option_tree_settings', array() );
  121.      
  122.      
  123.       $custom_settings = array(
  124.                              
  125.                               // This sections
  126.    
  127.    
  128.       'sections'        => array(
  129.           array(
  130.             'id'          => 'general',
  131.             'title'       => 'Site Settings'
  132.           )
  133.         ),
  134.        
  135.                                   // This settings
  136.                                  
  137.                                  //1. This settings One
  138.         'settings'        => array(
  139.           array(
  140.             'id'          => 'logo_text',
  141.             'label'       => 'Logo Text',
  142.             'desc'        => 'Use H1, H2, H3 tag',
  143.             'type'        => 'textarea',
  144.             'section'     => 'general'
  145.           ),
  146.          
  147.                                 //1. This settings two
  148.           array(
  149.             'id'          => 'footer_text',
  150.             'label'       => 'Footer Text',
  151.             'type'        => 'textarea',
  152.             'section'     => 'general'
  153.           )
  154.         )
  155.       );
  156.      
  157.       if ( $saved_settings !== $custom_settings ) {
  158.         update_option( 'option_tree_settings', $custom_settings );
  159.       }
  160.      
  161.     }
  162.      ?>
  163.  
  164.  
  165.    
  166.    
  167.     // for meta box call same as custom fields call just change the id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement