简体   繁体   中英

PHP fixed width image query

I'm trying to rewrite this query for a wordpress site to force the thumbnail images to be displayed at 200px x 200px, the actual image sizes are about 300x300.

 <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="65px" height="115px" />'; ?>

I've tried rewriting the image loop to:

<?php if (has_post_thumbnail( $loop->post->ID )) echo '<img src="'. get_the_post_thumbnail($loop->post->ID, 'shop_catalog').'" alt="Placeholder" width="300px" height="300px" />'; else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="65px" height="115px" />'; ?>

But this displays the path to the image, rather than the image itself.

Any idea what is going on?

I fixed this by resizing the image in the CSS. Doh!

#posts img{
    width: 100%;
    height:100%;
}

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM