Php WordPress以自定义模式获取帖子缩略图

Php WordPress以自定义模式获取帖子缩略图,php,html,wordpress,thumbnails,codex,Php,Html,Wordpress,Thumbnails,Codex,现在,我为每篇文章提供了两种尺寸的缩略图: $big = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail_600x200' ); $small = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail_200x100' ); 我试图实现的是使用以下模式显示帖子: 发帖1-[大拇指辫]

现在,我为每篇文章提供了两种尺寸的缩略图:

$big = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail_600x200' );
$small = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail_200x100' );
我试图实现的是使用以下模式显示帖子:

发帖1-[大拇指辫]
Post 2-[小拇指尾]
Post 3-[小拇指尾]
发布4-[big thumbail]
邮政5-[小拇指辫]
邮政6-[小拇指尾]

实际上,帖子会显示大-小-小-大-小-小等等

有什么想法吗?多谢各位

这是我的帖子:

<?php foreach ($posts as $post) { 
    $big = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail_600x200' );
    $small = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail_200x100' );

    if ( $big ) { ?>
        <img src="<?php echo $big['0']; ?>" />
    <?php }else{ ?>
        <img src="http://placehold.it/600x200/7f8c8d/ffffff" alt="Featured image missing"/>
    <?php } ?>
<?php } ?>

" />

在功能外制作一个计数器

在函数内部,递增计数器。但在此之前,请检查它是否countr%3==0

如果是,则显示大缩略图

<?php
 $counter = 0;
 foreach ($posts as $post) {  
        if($counter %3 == 0)
        {
           $big = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail_600x200' );
        }else{
           $small = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail_200x100' );
        }

    if ( $big ) { ?>
        <img src="<?php echo $big['0']; ?>" />
    <?php }else{ ?>
        <img src="http://placehold.it/600x200/7f8c8d/ffffff" alt="Featured image missing"/>
    <?php } ?>
  counter++; //increase the counter
<?php } ?>

" />
计数器++//增加计数器

如果每个帖子都增加一个指示器,从值3开始,你总是做一个模运算,怎么样

if(($i % 3) == 0) { 
  use big 
} else {
  use small
}
$i++;

@Rikesh你能帮我解决这个问题吗?“怎么可能呢?”里克什补充道each@Helper我的解决方案有效吗?@user299779是的。非常感谢。