Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Display CMB2 file_list item*/
- ----------------------------------
- <?php
- $images = get_post_meta($post->ID, 'light_image', true);
- foreach( $images as $image ) {
- echo '
- <img src="' . $image. '" alt="" />';
- }
- ?>
- / Display CMB2 file_list item with image title its mainly needed for lightbox
- <?php
- $images_list = get_post_meta($post->ID, 'galery_list', true);
- foreach( $images_list as $attachment_id => $attachment_url ) {
- $attachment_title = get_the_title($attachment_id);
- echo '<a title="'.$attachment_title.'" href="' . $attachment_url. '"></a>';
- } ?>
- / Display CMB2 file_list item with image crop size its mainly needed for lightbox
- <ul class="slides">
- <?php
- $idd = get_the_ID();
- $images = get_post_meta($idd, 'gallery_lis', true);
- if ( $images ) {
- foreach ( $images as $attachment_id => $img_full_url ) {
- // image with img tag into a tag
- $attachment_id;
- // image src only
- $img_full_url;
- // image with img tag into a tag with crop size
- $full = wp_get_attachment_link($attachment_id, 'crop_name');
- // img src with crop size
- $image_attributes = wp_get_attachment_image_src( $attachment_id, 'gall-image' );
- echo $image_attributes[0];
- echo "<li>";
- echo $full;
- echo "</li>";
- }
- }
- ?>
- </ul>
- resource : https://goo.gl/X6fy84
- /*Display CMB2 checkbox field with condition*/
- ----------------------------------
- <?php
- $idd = get_the_ID();
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '' );
- $video_url= get_post_meta($idd, 'video_url', true);
- $video_check= get_post_meta($idd, 'video_checkbox', true);
- if($video_check == 'on'){
- $img_linkk = $video_url;
- $imag_clss = 'mfp-iframe';
- } else{
- $img_linkk = $image[0];
- $imag_clss = 'gallery-items';
- } ?>
- <a class="<?php echo $imag_clss; ?>" title="<?php the_title();?>" href="<?php echo $img_linkk; ?>"></a>
- ---------- or -------------
- <?php $pdfpop = get_post_meta($post->ID, 'pdf-pop', true); ?>
- <?php if($pdfpop == 'on'):?>
- //condition content
- <?php else :?>
- //default content
- <?php endif; ?>
- /*Display CMB2 checkbox field with condition into query*/
- ----------------------------------
- 'meta_query' => array(
- array(
- 'key' => 'feature_checkbox',
- 'value' => 'on',
- 'compare' => 'LIKE',
- ),
- ),
- /*Display CMB2 select field with condition*/
- ----------------------------------
- <?php
- $idd = get_the_ID();
- $select_big = get_post_meta($idd, 'select_big', true);
- if($select_big == 'Big'){
- $namdilam = 'grid-item--width2';
- } else{
- $namdilam = 'small_grid';
- }
- ?>
- <?php
- if($select_big == 'Big'){
- the_post_thumbnail('gallr-big');
- } else{
- the_post_thumbnail('galler-small');
- }
- ?>
- /*Display CMB2 Date field*/
- ----------------------------------
- <?php
- $date = get_post_meta($post->ID, 'light_image', true);
- echo date("d/m/y", $date );
- ?>
- /*Display CMB2 Group item*/
- ----------------------------------
- <?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'];
- if ( isset( $entry['product_image'] ) ) $product_image = esc_html( $entry['product_image'] ); ?>
- <li>
- ?>
- <div class="escorts_single_testimonial fix">
- <div class="escorts_test_cont fix">
- <p>“<?php echo $product_description; ?>”</p>
- <img src="<?php echo $product_image; ?>" alt="" />
- </div>
- <div class="escorts_test_owner fix">
- <p>– <?php echo $product_name; ?></p>
- </div>
- </div>
- <?php } ?>
- </div>
- <?php } ?>
- Limit to specific page template
- ==================================
- $cmb = new_cmb2_box( array(
- 'id' => 'contact-information',
- 'title' => 'Contact Information',
- 'object_types' => array( 'page' ), // post type
- 'show_on' => array( 'key' => 'page-template', 'value' => 'template-contact.php' ),
- 'context' => 'normal', // 'normal', 'advanced', or 'side'
- 'priority' => 'high', // 'high', 'core', 'default' or 'low'
- 'show_names' => true, // Show field names on the left
- ) );
- Allow metabox to show up everywhere except a specified list of page IDs
- --------------------------------------------------------------------------
- add_action( 'cmb2_init', 'cmb2_add_metabox' );
- function cmb2_add_metabox() {
- $cmb = new_cmb2_box( array(
- 'id' => 'metabox',
- 'title' => __( 'Metabox Title', 'cmb2' ),
- 'object_types' => array( 'page', 'banner-items' ),
- 'context' => 'normal',
- 'priority' => 'default',
- 'exclude_ids' => array( 1, 2, 3, 55 ), // Exclude metabox on these post-ids
- 'show_on_cb' => 'cmb2_exclude_for_ids',
- ) );
- $cmb->add_field( array(
- 'name' => __( 'this is test', 'cmb2' ),
- 'id' => 'baner_img',
- 'type' => 'file',
- ) );
- }
- function cmb2_exclude_for_ids( $cmb ) {
- $ids_to_exclude = $cmb->prop( 'exclude_ids', array() );
- $excluded = in_array( $cmb->object_id(), $ids_to_exclude, false );
- return ! $excluded;
- }
- cmb2 custom group field
- =========================
- This code for make group field as your requirement into cmb2 config.php
- -----------------------------------------------------------------------
- $dim_group = $products_cmb->add_field( array(
- 'id' => $prefix.'product-dim',
- 'type' => 'group',
- 'description' => __( 'Enter Your Technical Data ', 'cmb' ),
- 'name' => __('Technical Data ', 'ecomed'),
- 'options' => array(
- 'group_title' => __( 'Data Group {#}', 'ecomed' ), // since version 1.1.4, {#} gets replaced by row number
- 'add_button' => __( 'Add Another Data', 'cmb' ),
- 'remove_button' => __( 'Remove Data', 'cmb' ),
- 'sortable' => true, // beta
- ),
- ) );
- // Id's for group's fields only need to be unique for the group. Prefix is not needed.
- $products_cmb->add_group_field( $dim_group, array(
- 'name' => 'Referência',
- 'id' => 'ref',
- 'type' => 'text',
- ) );
- // Id's for group's fields only need to be unique for the group. Prefix is not needed.
- $products_cmb->add_group_field( $dim_group, array(
- 'name' => 'Avanço',
- 'id' => 'avg',
- 'type' => 'text',
- ) );
- // Id's for group's fields only need to be unique for the group. Prefix is not needed.
- $products_cmb->add_group_field( $dim_group, array(
- 'name' => 'Descrição',
- 'id' => 'desc',
- 'type' => 'textarea',
- ) );
- // Id's for group's fields only need to be unique for the group. Prefix is not needed.
- $products_cmb->add_group_field( $dim_group, array(
- 'name' => 'Unidade',
- 'id' => 'unit',
- 'type' => 'text',
- ) );
- this code for display them
- ---------------------------------------
- <?php
- $product_dim = get_post_meta( get_the_ID(), $prefix.'product-dim', true );
- foreach ( (array) $product_dim as $key => $entry ) {
- $ref = $avg = $desc = $unit = '';
- if ( isset( $entry['ref'] ) )
- $ref = esc_html( $entry['ref'] );
- if ( isset( $entry['avg'] ) )
- $avg = esc_html( $entry['avg'] );
- if ( isset( $entry['desc'] ) )
- $desc = esc_html( $entry['desc'] );
- if ( isset( $entry['unit'] ) )
- $unit = esc_html( $entry['unit'] );
- ?>
- <div class="sproduct_table_col">
- <div class="sproduct_row_ref"><p><?php echo $ref; ?></p></div>
- <div class="sproduct_row_avg"><p><?php echo $avg; ?></p></div>
- <div class="sproduct_row_des"><p><?php echo $desc; ?></p></div>
- <div class="sproduct_row_unit"><p><?php echo $unit; ?></p></div>
- </div>
- <?php }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement