Advertisement
firoze

Promo and Font Icon changing by users CMB

Oct 30th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.76 KB | None | 0 0
  1. Promo font awesome icon easily changing by users
  2. // example-function.php
  3.  
  4. $meta_boxes['test_metabox'] = array(
  5.         'id'         => 'test_metabox',
  6.         'title'      => __( 'Font Awesome', 'cmb' ),
  7.         'pages'      => array( 'acme_product', ), // Post type
  8.         'context'    => 'normal',
  9.         'priority'   => 'high',
  10.         'show_names' => true, // Show field names on the left
  11.         // 'cmb_styles' => true, // Enqueue the CMB stylesheet on the frontend
  12.         'fields'     => array(
  13.             array(
  14.                 'name'       => __( 'Font Awesome', 'cmb' ),
  15.                 'desc'       => __( 'write your icon name', 'cmb' ),
  16.                 'id'         =>'promo-icon',
  17.                 'type'       => 'text',
  18.                 'show_on_cb' => 'cmb_test_text_show_on_cb', // function should return a bool value
  19.                 // 'sanitization_cb' => 'my_custom_sanitization', // custom sanitization callback parameter
  20.                 // 'escape_cb'       => 'my_custom_escaping',  // custom escaping callback parameter
  21.                 // 'on_front'        => false, // Optionally designate a field to wp-admin only
  22.                 // 'repeatable'      => true,
  23.             ),
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. // custom post promos (custom-post.php)
  32.  
  33. function create_post_type() {
  34.   register_post_type( 'acme_product',
  35.     array(
  36.       'labels' => array(
  37.         'name' => __( 'Products' ),
  38.         'singular_name' => __( 'Product' ),
  39.         'add_new'=>_('Add New product')
  40.       ),
  41.       'public' => true,
  42.       'has_archive' => true,
  43.       'rewrite'=> array( 'slug' => 'product' ),
  44.       'supports'=> array( 'title', 'editor', 'custom-fields', 'author', 'comments', '' )
  45.     )
  46.   );
  47. }
  48. add_action( 'init', 'create_post_type' );
  49.  
  50.  
  51. // From html page
  52.  
  53.         <div class="promo_content_area fix">
  54.             <div class="container">
  55.                 <div class="row">
  56.                         <?php
  57.                         global $post;
  58.                         $args = array( 'posts_per_page' => 4, 'post_type'=> 'acme_product');
  59.                         $myposts = get_posts( $args );
  60.                         foreach( $myposts as $post ) : setup_postdata($post); ?>
  61.                         <?php
  62.                         $promo_icon = get_post_meta( $post->ID, 'promo-icon', true );
  63.                         ?>
  64.                         <div class="col-md-3">
  65.                         <div class="promo_content">                    
  66.                             <?php if($promo_icon):?>
  67.                             <i class="fa fa-<?php echo $promo_icon;?> icon-all"></i>
  68.                             <?php else:?>
  69.                                 <i class="fa fa-home icon-all"></i>
  70.                             <?php endif;?>
  71.                
  72.                             <h2><?php the_title();?></h2>
  73.                             <?php the_content();?>
  74.                         </div>
  75.                         </div>
  76.                         <?php endforeach;?>
  77.                 </div>
  78.             </div>
  79.         </div>
  80.  
  81.  
  82.  
  83.  
  84.  
  85. // have to show in (functions.php)
  86.  
  87.  
  88. include_once('inc/custom-posts.php');
  89.    
  90.    
  91. // Initialize the metabox class
  92.  
  93. function be_initialize_cmb_meta_boxes() {
  94.     if ( !class_exists( 'cmb_Meta_Box' ) ) {
  95.         require_once( 'inc/cmb/init.php' );
  96.     }
  97. }  
  98. add_action( 'init', 'be_initialize_cmb_meta_boxes', 9999 );
  99.    
  100.    
  101. include_once('inc/cmb/example-functions.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement