実現したいこと
条件分岐で画像がJPGかどうか判断して、JPG画像だった場合に出力されたhtmlのimgにclass=jpgimageと追加したいです
前提
カテゴリーページにサムネイル画像が並んでいます。
今まではPNG画像だけだったので、
<?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php $post_title= get_the_title()."のプリント"; the_post_thumbnail(array( 80,80 ), array( 'alt' =>$post_title,)); ?></a></li> <?php endwhile; ?>
と記載していましたが、
JPG画像を増やすことになり
条件分岐で画像がJPGかどうか判断して、JPG画像だった場合に出力されたhtmlのimgにclass=jpgimageと追加したいのです。
試したこと
自分なりに調べて
<?php while (have_posts()) : the_post(); ?> <?php $img_url = get_the_post_thumbnail_url(get_the_ID(),'full') ?> <?php if(exif_imagetype($img_url) == IMAGETYPE_JPEG): ?> <li><a href="<?php the_permalink(); ?>"><?php $post_title= get_the_title()."のプリント"; the_post_thumbnail(array( 80,80 ), array( 'alt' =>$post_title,), array('class' => 'jpgimage')); ?></a></li> <?php else: ?> <li><a href="<?php the_permalink(); ?>"><?php $post_title= get_the_title()."のプリント"; the_post_thumbnail(array( 80,80 ), array( 'alt' =>$post_title,)); ?></a></li> <?php endif; ?> <?php endwhile; ?>
などとやってみましたが、上手くいきませんでした。
どうかご教授宜しくお願い致します。