繁体   English   中英

更改wordpress页面上的缩略图大小

[英]Change post thumbnail size on wordpress page

我制作了一个单独的wordpress页面来显示我的所有特色图像并且它们显示但是我需要帮助如何使它们显示到它们的实际尺寸而不是真正的小图像。

 <?php
$the_query = new WP_Query();
$the_query->query("cat=4&nopaging=true");

if ($the_query->have_posts()) : 
while($the_query->have_posts()) : $the_query->the_post();

  if(has_post_thumbnail()) : 
    the_post_thumbnail();
  endif;

endwhile; 
endif; 
wp_reset_postdata();
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); 
?>

<img src='<?php echo $image[0]; ?>' />

这是我的代码,现在页面是http://rickwarren.veracitycolab.com/banners/

谢谢!

这是我的新代码看起来像什么,图像仍然是相同的想法?

 <?php
$the_query = new WP_Query();
$the_query->query("cat=4&nopaging=true");
if ($the_query->have_posts()) : 
while($the_query->have_posts()) : $the_query->the_post();

  if(has_post_thumbnail()) : 
    the_post_thumbnail();
  endif;

endwhile; 
endif; 
wp_reset_postdata();
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
?>

如果在添加“完整”参数后仍未更改,则可能需要尝试重新生成缩略图插件: http//wordpress.org/extend/plugins/regenerate-thumbnails/

通常,当我一直在使用自定义缩略图大小时,它对我有帮助。

wp_get_attachment_image_src()的第二个参数是要返回的图像的大小。 在这里使用full应该会给你全尺寸的图像。

$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );

编辑:当然,这部分代码没有做任何事情,因为它在循环之外。

将第8行更改为the_post_thumbnail('full');

您可以删除以$image...开头的行之后的所有内容。 法典页面在这里

传递wp_get_attachment_image_src(...)一个大小参数。 在你的情况下,你想要'完整',所以wp_get_attachment_image_src( $post->ID, 'full' ) 来自法典的该职能

$ size(字符串/数组)(可选)为图像附件显示的图像大小:字符串关键字(缩略图,中,大或全)或表示宽度和高度的2项数组,例如数组(32) ,32)。 从版本2.5开始,此参数不会影响媒体图标的大小,这些图标始终以其原始大小显示。

  Default: thumbnail 

CSS规则仍然可以“缩小”图像,因此如果它不起作用,请检查HTML源中的URL以确认正在请求正确的图像,然后检查样式表。

暂无
暂无

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

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