Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- =======================================
- // Dynamic CMB2 Group type
- ===================================
- // This is for custom-metabox.php
- -------------------------------
- function review_sample_metaboxes( $meta_boxes_testi ) {
- $meta_boxes_testi['testimonial_metabox'] = array(
- 'id' => 'testimonial_metabox',
- 'title' => 'Escorts Testimonials Information',
- 'pages' => array('slider-items'), // post type
- 'context' => 'normal',
- 'priority' => 'high',
- 'show_names' => true, // Show field names on the left
- 'fields' => array(
- array(
- 'id' => 'repeat_group',
- 'type' => 'group',
- 'options' => array(
- 'group_title' => __( 'Testimonial {#}', 'cmb2' ), // since version 1.1.4, {#} gets replaced by row number
- 'add_button' => __( 'Add Another Entry', 'cmb2' ),
- 'remove_button' => __( 'Remove Entry', 'cmb2' ),
- 'sortable' => true, // beta
- ),
- // Fields array works the same, except id's only need to be unique for this group. Prefix is not needed.
- 'fields' => array(
- array(
- 'name' => 'Testimonial Author Name',
- 'id' => 'author_testimonial',
- 'type' => 'text',
- // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
- ),
- array(
- 'name' => 'Testimonial Description',
- 'description' => 'Write a short Testimonial description for this entry',
- 'id' => 'testimonial_desc',
- 'type' => 'textarea',
- ),
- ),
- ),
- ),
- );
- return $meta_boxes_testi;
- // This is for display fronted
- -------------------------------
- <?php
- $meta_entries_pre = get_post_meta( get_the_ID(), 'repeat_group', true );
- $meta_entries_int = array_reverse( $meta_entries_pre );
- $meta_entries = array_slice( $meta_entries_int, 0, 3 );
- if( ! empty( $meta_entries ) ) { ?>
- <div class="escrts_testimonials_content fix">
- <?php foreach ( (array) $meta_entries as $key => $entry ) {
- $product_name = $product_description = $meta_link = '';
- if ( isset( $entry['author_testimonial'] ) ) $product_name = $entry['author_testimonial'];
- if ( isset( $entry['testimonial_desc'] ) ) $product_description = $entry['testimonial_desc'];
- ?>
- <div class="escorts_single_testimonial fix">
- <div class="escorts_test_cont fix">
- <p>“<?php echo $product_description; ?>”</p>
- </div>
- <div class="escorts_test_owner fix">
- <p>– <?php echo $product_name; ?></p>
- </div>
- </div>
- <?php } ?>
- </div>
- <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment