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

时间:2012-10-15 18:00:13

标签: php html css wordpress

我制作了一个单独的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' );
?>

3 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

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...开头的行之后的所有内容。 Codex page here

答案 2 :(得分:1)

也传递wp_get_attachment_image_src(...)尺寸参数。在您的情况下,您需要“完整”,所以wp_get_attachment_image_src( $post->ID, 'full' )。来自the Codex for that function

  

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

    Default: thumbnail

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

相关问题