RUSSEL86

USE CMB2 Group type

Apr 9th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. <?
  2.  
  3. =======================================
  4. // Dynamic CMB2 Group type
  5. ===================================
  6. // This is for custom-metabox.php
  7. -------------------------------
  8.  
  9. function review_sample_metaboxes( $meta_boxes_testi ) {
  10. $meta_boxes_testi['testimonial_metabox'] = array(
  11. 'id' => 'testimonial_metabox',
  12. 'title' => 'Escorts Testimonials Information',
  13. 'pages' => array('slider-items'), // post type
  14. 'context' => 'normal',
  15. 'priority' => 'high',
  16. 'show_names' => true, // Show field names on the left
  17. 'fields' => array(
  18. array(
  19. 'id' => 'repeat_group',
  20. 'type' => 'group',
  21. 'options' => array(
  22. 'group_title' => __( 'Testimonial {#}', 'cmb2' ), // since version 1.1.4, {#} gets replaced by row number
  23. 'add_button' => __( 'Add Another Entry', 'cmb2' ),
  24. 'remove_button' => __( 'Remove Entry', 'cmb2' ),
  25. 'sortable' => true, // beta
  26. ),
  27. // Fields array works the same, except id's only need to be unique for this group. Prefix is not needed.
  28. 'fields' => array(
  29. array(
  30. 'name' => 'Testimonial Author Name',
  31. 'id' => 'author_testimonial',
  32. 'type' => 'text',
  33. // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
  34. ),
  35. array(
  36. 'name' => 'Testimonial Description',
  37. 'description' => 'Write a short Testimonial description for this entry',
  38. 'id' => 'testimonial_desc',
  39. 'type' => 'textarea',
  40. ),
  41. ),
  42. ),
  43. ),
  44. );
  45.  
  46. return $meta_boxes_testi;
  47.  
  48.  
  49.  
  50.  
  51. // This is for display fronted
  52. -------------------------------
  53.  
  54. <?php
  55. $meta_entries_pre = get_post_meta( get_the_ID(), 'repeat_group', true );
  56. $meta_entries_int = array_reverse( $meta_entries_pre );
  57. $meta_entries = array_slice( $meta_entries_int, 0, 3 );
  58. if( ! empty( $meta_entries ) ) { ?>
  59.  
  60. <div class="escrts_testimonials_content fix">
  61.  
  62. <?php foreach ( (array) $meta_entries as $key => $entry ) {
  63. $product_name = $product_description = $meta_link = '';
  64. if ( isset( $entry['author_testimonial'] ) ) $product_name = $entry['author_testimonial'];
  65. if ( isset( $entry['testimonial_desc'] ) ) $product_description = $entry['testimonial_desc'];
  66. ?>
  67. <div class="escorts_single_testimonial fix">
  68. <div class="escorts_test_cont fix">
  69. <p>“<?php echo $product_description; ?>”</p>
  70. </div>
  71. <div class="escorts_test_owner fix">
  72. <p>– <?php echo $product_name; ?></p>
  73. </div>
  74. </div>
  75. <?php } ?>
  76. </div>
  77. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment