本文介绍了WordPress的循环:如何将每3个职位包装到一个div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?php query_posts('cat = 6'); ?>
<?php if(have_posts()):?>
< div>
<?php $ counter = 3; ?>
<?php the_post_thumbnail(); ?>
<?php $ counter ++; ?>
< / div>
<?php endif; ?>
但是不行! :/
谢谢!
解决方案
感谢您的支持! :)
我尝试了两种解决方案,但没有工作,
我结束了这一点,完美的作品!
<?php query_posts('cat = 6'); ?>
<?php $ variable = 0;?>
< div>
< a href =<?php echo get_post_meta($ post-> ID,'colaborador-link',true);?>目标= 空白 >
<?php the_post_thumbnail(); ?>
< / a>
<?php $ variable + = 1; ?>
<?php} else {?>
<?php $ variable = 1; ?>
< / div>
< div>
< a href =<?php echo get_post_meta($ post-> ID,'colaborador-link',true);?>目标= 空白 >
<?php the_post_thumbnail(); ?>
< / a>
<?php}?>
< / div>
I'm trying this:
<?php query_posts('cat=6'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div>
<?php $counter=3; ?>
<?php the_post_thumbnail(); ?>
<?php $counter++; ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
But it's not working! :/Thank you!
解决方案
Thanks for your support guys! :) I tried both solutions but didn't work,I ended up with this and works perfectly!
<?php query_posts('cat=6'); ?>
<?php $variable=0;?>
<div>
<?php while ( have_posts() ) : the_post(); ?>
<?php if(($variable+1)<4){ ?>
<a href="<?php echo get_post_meta($post->ID, 'colaborador-link', true); ?>" target="blank">
<?php the_post_thumbnail(); ?>
</a>
<?php $variable+=1; ?>
<?php }else{ ?>
<?php $variable=1; ?>
</div>
<div>
<a href="<?php echo get_post_meta($post->ID, 'colaborador-link', true); ?>" target="blank">
<?php the_post_thumbnail(); ?>
</a>
<?php }?>
<?php endwhile; ?>
</div>
这篇关于WordPress的循环:如何将每3个职位包装到一个div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!