/** * HTML output of thumbnail field * * @param object $post The post object * @param array $fargs The settings of this field * * @return string */ static function _field_thumbnail($post, $fargs) { $dargs = PT_CV_Functions::get_global_variable('dargs'); // Get layout format $layout_format = $fargs['layout-format']; // Get thumbnail settings $fargs = $fargs['thumbnail']; $html = ''; // Get post ID $post_id = $post->ID; // Custom args for get_the_post_thumbnail function $thumbnail_class = array(); $thumbnail_class[] = PT_CV_PREFIX . 'thumbnail'; $thumbnail_class[] = isset($fargs['style']) ? $fargs['style'] : ''; if ($layout_format === '2-col') { $thumbnail_class[] = isset($fargs['position']) ? 'pull-' . $fargs['position'] : 'pull-left'; } $gargs = array('class' => apply_filters(PT_CV_PREFIX_ . 'field_thumbnail_class', implode(' ', array_filter($thumbnail_class)))); // Get thumbnail dimensions $dimensions = PT_CV_Functions::field_thumbnail_dimensions($fargs); $dimensions = (array) apply_filters(PT_CV_PREFIX_ . 'field_thumbnail_dimension_output', $dimensions, $fargs); // Check if has thumbnail ( has_post_thumbnail doesn't works ) $thumbnail_id = get_post_thumbnail_id($post_id); // Check if user doesn't want to load thumbnail: field_thumbnail_load = 0 $load_thumbnail = !empty($thumbnail_id) && apply_filters(PT_CV_PREFIX_ . 'field_thumbnail_load', 1); if ($load_thumbnail) { $thumbnail_size = count($dimensions) > 1 ? $dimensions : $dimensions[0]; $html = wp_get_attachment_image((int) $thumbnail_id, $thumbnail_size, false, $gargs); $html = apply_filters(PT_CV_PREFIX_ . 'field_thumbnail_image', $html, $post_id, $dimensions, $fargs); } else { $html = apply_filters(PT_CV_PREFIX_ . 'field_thumbnail_not_found', $html, $post, $dimensions, $gargs); } // Add link to thumbnail $oargs = isset($dargs['other-settings']) ? $dargs['other-settings'] : array(); $html = self::_field_href($oargs, $post, $html); return $html; }
/** * HTML output of thumbnail field * * @param object $post The post object * @param array $_fargs The settings of this field * * @return string */ static function _field_thumbnail($post, $_fargs) { $layout_format = $_fargs['layout-format']; // Get thumbnail settings $fargs = $_fargs['thumbnail']; // Thumbnail class $thumbnail_position = 'default'; $thumbnail_class = array(); $thumbnail_class[] = PT_CV_PREFIX . 'thumbnail'; $thumbnail_class[] = isset($fargs['style']) ? $fargs['style'] : ''; if ($layout_format === '2-col') { $thumbnail_position = isset($fargs['position']) ? $fargs['position'] : 'left'; $thumbnail_class[] = 'pull-' . $thumbnail_position; } $gargs = array('class' => apply_filters(PT_CV_PREFIX_ . 'field_thumbnail_class', implode(' ', array_filter($thumbnail_class)))); /** * @since 1.7.5 * able to disable responsive image of WordPress 4.4 */ if (PT_CV_Functions::setting_value(PT_CV_PREFIX . 'field-thumbnail-nowprpi')) { $gargs['srcset'] = 1; } // Get thumbnail dimensions $dimensions = (array) apply_filters(PT_CV_PREFIX_ . 'field_thumbnail_dimension_output', PT_CV_Functions::field_thumbnail_dimensions($fargs), $fargs); // Check if has thumbnail ( has_post_thumbnail doesn't works ) $thumbnail_id = get_post_thumbnail_id($post->ID); // Check if user doesn't want to load thumbnail: field_thumbnail_load = 0 $load_thumbnail = !empty($thumbnail_id) && apply_filters(PT_CV_PREFIX_ . 'field_thumbnail_load', 1); $html = ''; if ($load_thumbnail) { $thumbnail_size = count($dimensions) > 1 ? $dimensions : $dimensions[0]; $html = wp_get_attachment_image((int) $thumbnail_id, $thumbnail_size, false, $gargs); $html = apply_filters(PT_CV_PREFIX_ . 'field_thumbnail_image', $html, $post, $dimensions, $fargs); } // If no thumbnail if (empty($html)) { $html = apply_filters(PT_CV_PREFIX_ . 'field_thumbnail_not_found', $html, $post, $dimensions, $gargs); } // Add link to thumbnail $dargs = PT_CV_Functions::get_global_variable('dargs'); $oargs = isset($dargs['other-settings']) ? $dargs['other-settings'] : array(); $html = self::_field_href($oargs, $post, $html, implode(' ', array(PT_CV_PREFIX . 'href-thumbnail', PT_CV_PREFIX . 'thumb-' . $thumbnail_position))); return $html; }