Content Views Pro version 5.5.0 and higher
Since Content Views Pro version 5.5.0, you can easily show image custom field as thumbnail without coding.
Here is the configuration in Display Settings >> Fields Settings >> Thumbnail of the View to show any image custom field as thumbnail:
Content Views Pro version 5.4.1 and prior
For previous Pro versions, to show the custom field as thumbnail, please follow steps below:
- In the View where you want to show the custom field as thumbnail, select the Show Thumbnail checkbox in Display Settings >> Fields settings.
- Under Display Settings >> Fields settings >> Thumbnail >> Substitute, please configure as below:
- Add this code to file functions.php of your active theme:
// Content Views Pro - Use custom field as thumbnail add_filter( 'pt_cv_field_content_excerpt', 'cvp_theme_custom_field_as_thumbnail', 999, 3 ); function cvp_theme_custom_field_as_thumbnail( $args, $fargs, $post ) { if ( empty( $fargs ) ) { $custom_field = 'CUSTOM_FIELD'; $fval = null; if ( class_exists( 'CVP_CTF' ) ) { $ctf = new CVP_CTF( $custom_field, $post, true, '' ); $fval = isset( $ctf->field_value ) ? $ctf->field_value : $fval; } if ( empty( $fval ) ) { $meta = get_post_meta( $post->ID ); $fval = !empty( $meta[ $custom_field ][ 0 ] ) ? $meta[ $custom_field ][ 0 ] : $fval; } $args = $fval ? sprintf( "<img src='%s'>", esc_url( $fval ) ) : $args; } return $args; }
(replace CUSTOM_FIELD with name/key of your custom field).
Thank you,