繁体   English   中英

如何调整wordpress页面中附加图像的大小

[英]How to resize an image attached in the page in wordpress

我需要降低在wordpress页面中附加的图像的高度。 我尝试了几种方法,但是无法解决它。当我在img src中添加图像大小Topbannerimg时,它没有任何改变。

我的wp_query显示图片

<?php 
$homepage = get_page_by_title('Top Banner');
$attachments = get_posts( array(
     'post_type' => 'attachment',
     'posts_per_page' => -1,
     'post_parent' => $homepage->ID,
) );
if ( $attachments ) {
  echo '<section class="topBanner">';
    foreach ( $attachments as $attachment ) { ?>          
      <a href="<?php if($attachment->post_excerpt){echo $attachment->post_excerpt;}else{echo "#";}?>">
            <img src="<?php echo wp_get_attachment_url($attachment->ID); ?>">
      </a>

    <?php }
  echo '</section>';
}
wp_reset_postdata();?>

在functions.php中提到的大小

add_image_size( 'TopBannerImg', 1800, 500, true );

您可以使用wp_get_attachment_image函数显示图像。 请参考: https : //developer.wordpress.org/reference/functions/wp_get_attachment_image/ 将图像缩略图名称作为第二个参数传递。

签出此代码:

第一个参数表示宽度,第二个参数表示高度。

<?php the_post_thumbnail( array( 480, 277 ) ); ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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