ДД!Сайт: thirteen(точка)kz
Проблема с отображением миниатюр на сайте.
Вставляю миниатюру. После она должна отображаться в виде картинки на сайте (по задумке). Но она по какой то причине не добавляется на сайте.
Для корректного понимания проблемы, пройдите на сайте в раздел: Команда (thirteen(точка)kz/our-team/) < не забудьте поменять слово "точка" на знак
Смотрим работника "Сергей Шишов" и понимаем, что картинка не отображается корректно.
Фрагмент файла core-function.php в котором думаю и кроется сама проблема
Проблема с отображением миниатюр на сайте.
Вставляю миниатюру. После она должна отображаться в виде картинки на сайте (по задумке). Но она по какой то причине не добавляется на сайте.
Для корректного понимания проблемы, пройдите на сайте в раздел: Команда (thirteen(точка)kz/our-team/) < не забудьте поменять слово "точка" на знак
Смотрим работника "Сергей Шишов" и понимаем, что картинка не отображается корректно.
Фрагмент файла core-function.php в котором думаю и кроется сама проблема
| Код |
|---|
function dt_get_resized_img( $img, $opts, $resize = true, $is_retina = false ) {
$opts = apply_filters( 'dt_get_resized_img-options', $opts, $img );
if ( !is_array( $img ) || !$img || (!$img[1] && !$img[2]) ) {
return false;
}
if ( !is_array( $opts ) || !$opts ) {
if ( !isset( $img[3] ) ) {
$img[3] = image_hwstring( $img[1], $img[2] );
}
return $img;
}
if ( !isset($opts['hd_convert']) ) {
$opts['hd_convert'] = true;
}
$defaults = array( 'w' => 0, 'h' => 0 , 'zc' => 1, 'z' => 1 );
$opts = wp_parse_args( $opts, $defaults );
$w = absint( $opts['w'] );
$h = absint( $opts['h'] );
// If zoomcropping off and image smaller then required square
if ( 0 == $opts['zc'] && ( $img[1] <= $w && $img[2] <= $h ) ) {
return array( $img[0], $img[1], $img[2], image_hwstring( $img[1], $img[2] ) );
} else if ( 3 == $opts['zc'] || empty ( $w ) || empty ( $h ) ) {
if ( 0 == $opts['z'] ) {
dt_constrain_dim( $img[1], $img[2], $w, $h, true );
} else {
$p = absint( $img[1] ) / absint( $img[2] );
$hx = absint( floor( $w / $p ) );
$wx = absint( floor( $h * $p ) );
if ( empty( $w ) ) {
$w = $wx;
} else if ( empty( $h ) ) {
$h = $hx;
} else {
if ( $hx < $h && $wx >= $w ) {
$h = $hx;
} else if ( $wx < $w && $hx >= $h ) {
$w = $wx;
}
}
}
if ( $img[1] == $w && $img[2] == $h ) {
return array( $img[0], $img[1], $img[2], image_hwstring( $img[1], $img[2] ) );
}
}
$img_h = $h;
$img_w = $w;
if ( $opts['hd_convert'] && $is_retina ) {
$img_h *= 2;
$img_w *= 2;
}
if ( 1 == $opts['zc'] ) {
if ( $img[1] >= $img_w && $img[2] >= $img_h ) {
// do nothing
} else if ( $img[1] <= $img[2] && $img_w >= $img_h ) { // img=portrait; c=landscape
$cw_new = $img[1];
$k = $cw_new/$img_w;
$ch_new = $k * $img_h;
} else if ( $img[1] >= $img[2] && $img_w <= $img_h ) { // img=landscape; c=portrait
$ch_new = $img[2];
$k = $ch_new/$img_h;
$cw_new = $k * $img_w;
} else {
$kh = $img_h/$img[2];
$kw = $img_w/$img[1];
$kres = max( $kh, $kw );
$ch_new = $img_h/$kres;
$cw_new = $img_w/$kres;
}
if ( isset($ch_new, $cw_new) ) {
$img_h = absint(floor($ch_new));
$img_w = absint(floor($cw_new));
}
}
if ( $resize ) {
$file_url = aq_resize( $img[0], $img_w, $img_h, true, true, false );
}
if ( empty( $file_url ) ) {
$file_url = $img[0];
}
return array(
$file_url,
$w,
$h,
image_hwstring( $w, $h )
);
}
/**
* DT master get image function.
*
* @param $opts array
*
* @return string
*/
function dt_get_thumb_img( $opts = array() ) {
global $post;
$default_image = presscore_get_default_image();
$defaults = array(
'wrap' => '<a %HREF% %CLASS% %TITLE% %CUSTOM%><img %SRC% %IMG_CLASS% %SIZE% %ALT% %IMG_TITLE% /></a>',
'class' => '',
'alt' => '',
'title' => '',
'custom' => '',
'img_class' => '',
'img_title' => '',
'img_description' => '',
'img_caption' => '',
'href' => '',
'img_meta' => array(),
'img_id' => 0,
'options' => array(),
'default_img' => $default_image,
'prop' => false,
'echo' => true
);
$opts = wp_parse_args( $opts, $defaults );
$opts = apply_filters('dt_get_thumb_img-args', $opts);
// var_dump( $opts['options'] );
$original_image = null;
if ( $opts['img_meta'] ) {
$original_image = $opts['img_meta'];
} else if ( $opts['img_id'] ) {
$original_image = wp_get_attachment_image_src( $opts['img_id'], 'full' );
}
if ( !$original_image ) {
$original_image = $opts['default_img'];
}
// proportion
if ( $original_image && !empty($opts['prop']) && ( empty($opts['options']['h']) || empty($opts['options']['w']) ) ) {
$_prop = $opts['prop'];
$_img_meta = $original_image;
if ( $_prop > 1 ) {
$h = intval(floor($_img_meta[1] / $_prop));
$w = intval(floor($_prop * $h));
} else if ( $_prop < 1 ) {
$w = intval(floor($_prop * $_img_meta[2]));
$h = intval(floor($w / $_prop));
} else {
$w = $h = min($_img_meta[1], $_img_meta[2]);
}
if ( !empty($opts['options']['w']) ) {
$__prop = $h / $w;
$w = intval($opts['options']['w']);
$h = intval(floor($__prop * $w));
} else if ( !empty($opts['options']['h']) ) {
$__prop = $w / $h;
$h = intval($opts['options']['h']);
$w = intval(floor($__prop * $h));
}
$opts['options']['w'] = $w;
$opts['options']['h'] = $h;
}
if ( $opts['options'] ) {
if ( empty( $opts['options']['use_srcset'] ) ) {
$resized_image = dt_get_resized_img( $original_image, $opts['options'], true, dt_retina_on() && dt_is_hd_device() );
} else {
$resized_image = dt_get_resized_img( $original_image, $opts['options'], true, false );
$resized_image_hd = dt_get_resized_img( $original_image, $opts['options'], true, true );
$resized_image[0] .= ' 1x, ' . $resized_image_hd[0] .= ' 2x';
}
} else {
$resized_image = $original_image;
}
if ( $img_id = absint( $opts['img_id'] ) ) {
if ( '' === $opts['alt'] ) {
$opts['alt'] = get_post_meta( $img_id, '_wp_attachment_image_alt', true );
}
if ( '' === $opts['img_title'] ) {
$opts['img_title'] = get_the_title( $img_id );
}
}
$class = empty( $opts['class'] ) ? '' : 'class="' . esc_attr( trim($opts['class']) ) . '"';
$title = empty( $opts['title'] ) ? '' : 'title="' . esc_attr( trim($opts['title']) ) . '"';
$img_title = empty( $opts['img_title'] ) ? '' : 'title="' . esc_attr( trim($opts['img_title']) ) . '"';
$img_class = empty( $opts['img_class'] ) ? '' : 'class="' . esc_attr( trim($opts['img_class']) ) . '"';
$href = $opts['href'];
if ( !$href ) {
$href = $original_image[0];
}
$src = $resized_image[0];
if ( empty( $opts['options']['use_srcset'] ) ) {
// $src = dt_make_image_src_ssl_friendly( $src );
$src = str_replace( array(' '), array('%20'), $src );
$src_att = 'src="' . esc_url( $src ) . '"';
} else {
$src_att = 'srcset="' . esc_attr( $src ) . '"';
}
if ( empty($resized_image[3]) || !is_string($resized_image[3]) ) {
$size = image_hwstring($resized_image[1], $resized_image[2]);
} else {
$size = $resized_image[3];
}
$output = str_replace(
array(
'%HREF%',
'%CLASS%',
'%TITLE%',
'%CUSTOM%',
'%SRC%',
'%IMG_CLASS%',
'%SIZE%',
'%ALT%',
'%IMG_TITLE%',
'%RAW_TITLE%',
'%RAW_ALT%',
'%RAW_IMG_TITLE%',
'%RAW_IMG_DESCRIPTION%',
'%RAW_IMG_CAPTION'
),
array(
'href="' . esc_url( $href ) . '"',
$class,
$title,
strip_tags( $opts['custom'] ),
$src_att,
$img_class,
$size,
'alt="' . esc_attr( $opts['alt'] ) . '"',
$img_title,
esc_attr( $opts['title'] ),
esc_attr( $opts['alt'] ),
esc_attr( $opts['img_title'] ),
esc_attr( $opts['img_description'] ),
esc_attr( $opts['img_caption'] )
),
$opts['wrap']
);
if ( $opts['echo'] ) {
echo $output;
return '';
}
return $output;
}
/**
* Load presscore template.
*
* @param $slug string
* @param $name string
*/
function dt_get_template_part( $slug = '', $name = '' ) {
if ( empty( $slug ) ) {
return;
}
$dir_base = '/templates/';
get_template_part( $dir_base . $slug, $name );
}
/**
* Description here.
*
* @param $src string
*
* @return string
*
* @since presscore 0.1
*/
function dt_get_of_uploaded_image( $src ) {
if ( ! $src ) {
return '';
}
$uri = $src;
if ( ! parse_url( $src, PHP_URL_SCHEME ) ) {
if ( dt_maybe_uploaded_image_url( $src ) ) {
$uri = site_url( $src );
} else {
$uri = PRESSCORE_PRESET_BASE_URI . $src;
}
}
return $uri;
}
function dt_maybe_uploaded_image_url( $url ) {
$uploads = wp_upload_dir();
$baseurl = str_replace( site_url(), '', $uploads['baseurl'] );
$pattern = '/' . trailingslashit( basename( WP_CONTENT_URL ) );
return ( strpos( $url, $baseurl ) !== false || strpos( $url, $pattern ) !== false );
}
/**
* Parse str to array with src, width and height
* expample: image.jpg?w=25&h=45
*
* @param $str string
*
* @return array
*
* @since presscore 0.1
*/
function dt_parse_of_uploaded_image_src ( $str ) {
if ( empty( $str ) ) {
return array();
}
$res_arr = array();
$str_arr = explode( '?', $str );
$res_arr[0] = dt_get_of_uploaded_image( current( $str_arr ) );
// if no additional arguments specified
if ( ! isset( $str_arr[1] ) ) {
return array();
}
$args_arr = array();
wp_parse_str( $str_arr[1], $args_arr );
if ( isset( $args_arr['w'] ) && isset( $args_arr['h'] ) ) {
$res_arr[1] = intval( $args_arr['w'] );
$res_arr[2] = intval( $args_arr['h'] );
} else {
return array();
}
return $res_arr;
}
|
