【发布时间】:2015-11-19 23:31:04
【问题描述】:
在概览页面上,我只想显示带有文章链接的帖子缩略图。但拇指应该有不同的大小(5 个大小,交替)。类似的东西:
图片1:拇指大小1
图片 2:拇指大小2
图片 3:thumbsize3
图片 4:thumbsize4
图片 5:thumbsize5
图 6:thumbsize1
图片 7:thumbsize2
等等。
我知道此代码在均匀和不均匀的帖子之间有所不同:
<?php $i = 1; // Index setzen ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ($i % 2 == 1 ) {
echo 'CONTENT';
} ?>
<?php if ($i % 2 == 0 ) {
echo 'CONTENT';
}
$i++; // Index um 1 erhoehen
?>
<?php endwhile; ?>
<?php endif; ?>
那么如何更改此代码以满足我的需要?
更新:
这是我现在的代码:
<?php
$thumbname = 'thumbsize'.($i%5+1); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail( $thumbname ); ?></a>
<?php $i++; // Index um 1 erhoehen
?>
<?php endwhile; ?>
<?php endif; ?>
在我的functions.php中:
add_image_size( 'thumbsize2', 300, 350, true );
add_image_size( 'thumbsize3', 750, 350, true );
add_image_size( 'thumbsize4', 400, 350, true );
add_image_size( 'thumbsize5', 300, 350, true );
add_image_size( 'thumbsize6', 350, 350, true );
等等。 但是,缩略图具有完整的上传大小。
【问题讨论】:
标签: php wordpress thumbnails