我正在尝试使用设置后缩略图的宽度
the_post_thumbnail().
图像的宽度需要为210像素,但高度并不是固定的,因为所有图像的大小都不同.我试过了
the_post_thumbnail(阵列(210,0))
但这不起作用.有任何想法吗?
谢谢
The*_*pha 20
在你的functions.php中添加这个
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'category-thumb', 210, 9999 ); //210 pixels wide (and unlimited height)
}
Run Code Online (Sandbox Code Playgroud)
在主题的模板文件中使用它
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'category-thumb' ); } ?>
Run Code Online (Sandbox Code Playgroud)
对于默认缩略图,请在functions.php中添加
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 9999 ); // default Post Thumbnail dimensions
}
Run Code Online (Sandbox Code Playgroud)
参考: 这里.
| 归档时间: |
|
| 查看次数: |
15709 次 |
| 最近记录: |