wordpress缩略图的地址怎么怎么获取呢?很多时候如果是设计师的话,可能需要自己定制需要的部分,比如我只要图片地址,不需要链接,这时候就需要分解wordpress的缩略图函数了。查了很多wordpress的文档,都没有具体介绍。在一篇国外网站看到介绍。
我们知道wordpress缩略图首先要启用。然后可以根据自己主题的需要来定制缩略图的大小等。
To enable post thumbnail write this code in your theme functions.php file
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150, true ); //default Post Thumbnail dimensions (cropped)// additional image sizes
// delete the next line if you do not need additional image sizes
add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)
}
Code for post thumbnail display :
<?php
$default_attr = array(
'src' => $src,
'class' => "attachment-$size",
'alt' => trim(strip_tags( wp_postmeta->_wp_attachment_image_alt )),
'title' => trim(strip_tags( $attachment->post_title )),
);if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail($image_size , $default_attr);
}?>
从上面我们可以看到缩略图的地址、宽度、高度等。
- thumbnail src
- thumbnail width
- thumbnail height
so just write
<?php$thumbnail= wp_get_attachment_image_src ( get_post_thumbnail_id ($post->ID ),$image_size);?>
谢谢博主的教程了,收藏备用·
2013-03-26 11:09很高兴能帮到你的忙。
2013-05-06 03:01这个缩略图的功能实现有些难度啊
2013-07-09 02:34