我在wordpress中制作图库,我想更改默认缩略图大小,但它无法正常工作。当我将照片设置为后缩略图时自然尺寸为150x150的wordpress媒体选项我将缩略图大小更改为215 143.
在我的职能中
add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1240, 1240 );
}
我的图片库查询:
<ul id="stage">
<?php
// The Query
$the_query = new WP_Query( array( 'post_type' => 'flota', 'orderby' => 'title', 'order' => 'ASC' ) );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id ( $the_query->ID ), 'thumbnail' );
$full = wp_get_attachment_image_src( get_post_thumbnail_id ( $the_query->ID ), 'full' );
$cats = wp_get_object_terms( $post->ID, 'flota_category' );
$items = array();
foreach ( $cats as $cat ){
$slug = $cat->slug;
$items[] = $slug;
}
$counter = count($cats);
$i = 0;
?>
<li data-tags="<?php
foreach ( $items as $tag ){
if (++$i === $counter ){
$tags = $tag;
}
else{
$tags = $tag . ', ';
}
echo $tags;
}
?>"><a href="<?php echo $full[0] ?>" rel="lightbox[flota]"><img src="<?php echo $thumbnail[0] ?>" width="215" height="143" style="background:#ffffff;"></a></li>
<?php
endwhile;
?>
</ul>
答案 0 :(得分:2)
在functions.php中使用:
add_theme_support( 'post-thumbnails' );
add_image_size( 'gallery-thumb', 215, 143 );
每页的默认帖子数为10,这就是为什么您只能看到10张图片的原因。通过将查询更改为:
来覆盖此问题$the_query = new WP_Query( array( 'post_type' => 'flota', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1, ) );
在您的查询中将$ thumbnail和$ full替换为:
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), 'gallery-thumb' );
$full = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
然后使用http://wordpress.org/plugins/regenerate-thumbnails/之类的插件重新生成缩略图。
在一个循环中,get_post_thumbnail_id不需要设置ID,但如果您决定将其设置在别处,那么您需要查找$ post-&gt; ID而不是$ the_query-&gt; ID。设置$ global $ post;以及使用它时。