由于使用了放大镜脚本,我需要在文章中加载完整的图像(不是特色图像),即使客户正在选择缩略图。
例。。。应生成以下代码:
<img src="..../uploads/image.png" width="300" height="500" />
而不是
<img src="..../uploads/image-300x500.png" width="300" height="500" />
有人对此有很酷的片段吗?谢谢!
编辑:我的意思是文章中使用的图像,而不是帖子/特色/缩略图功能。
WordPress核心内置了四种有效的尺寸。
the_post_thumbnail('thumbnail'); // Thumbnail (default 150px x 150px max)
the_post_thumbnail('medium'); // Medium resolution (default 300px x 300px max)
the_post_thumbnail('large'); // Large resolution (default 640px x 640px max)
the_post_thumbnail('full'); // Original image resolution (unmodified)
最后一个是你正在寻找的。
下面返回 URL。全尺寸。
<?php if (has_post_thumbnail())
$imageUrl = wp_get_attachment_image_src(get_post_thumbnail_id(),'full');?>
<img alt="Post Thumbnail" src="<?php echo esc_url($imageUrl[0]); ?>">
对于博客图像,您可以使用 -
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<img alt="Post Thumbnail" src="<?php echo esc_url($imageUrl[0]); ?>">
<?php endif; ?>
如果要在代码中设置图像大小,可以在函数.php文件中使用以下代码
<?php add_image_size('product-size-large',300, 500, true);?>
然后在这里使用此大小
<?php $imageUrl = wp_get_attachment_image_src(get_post_thumbnail_id(),'product-size-large'); ?>
此外,有关更多选项,请参阅法典。
这是WordPress中自定义图像上传的代码
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'your-custom-size' => __( 'Your Custom Size Name' ),
) );
}
// Assuming your Media Library image has a post id of 24...
echo wp_get_attachment_image( 24, 'your-custom-size' );
您可以使用
the_post_thumbnail('full','true');以获取原始图像大小。 或您也可以使用
function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) {
$post = get_post( $post );
if ( ! $post ) {
return '';
}
$post_thumbnail_id = get_post_thumbnail_id( $post );
在您的函数中.php
您可以先获取图像缩略图,然后可以插入图像标签。在"get_post_thumbnail_id"中,您可以插入在代码中定义的任何大小。缩略图已经在函数中定义了大小.php。
<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail');?>
<img src="<?php echo esc_url($thumbnail['0']); ?>" alt="Post Thumbnail"/>