在 Wordpress 中使用 post_thumbnail 功能时,有没有办法确定图像的方向?我创建了两种不同的尺寸,我需要使用合适的尺寸,即
the_post_thumbnail( 'article-pic-horizontal' );
或
the_post_thumbnail( 'article-pic-vertical' );
最佳答案
接受更好的建议,但最终对我有用的是:
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
$imgmeta = wp_get_attachment_metadata( $post_thumbnail_id );
if ($imgmeta['width'] > $imgmeta['height']) {
...
} else {
...
}
https://stackoverflow.com/questions/7084382/