wordpress循环,每三分之一应用一些新内容 [英] wordpress loop, applying something new every third post
问题描述
我有这个循环,基本上在页面上显示一个块,其中有一个图像,类 gallerypic
的右边距为20px,它也有规则 float:left;
,问题在于每次创建第三个div时,都会从新行开始,因为边距会将其推到那里。所以理想情况下,每三分之一的帖子我想不要保证金,并应用div gallerypicright
或其他。
I have this loop which basically displays a block on the page with an image in it, the class gallerypic
has a margin of 20px on the right, it also has the rule float:left;
, the issue is every time the third div is created it starts on a new line, because the margin is pushing it there. So Ideally every third post I would like no margin, and to apply a div gallerypicright
or something.
我想知道有人有解决这个问题吗?可能是一个更简单的方法,它可以简单地阻止第三个边缘发生边缘问题?我需要在另外两个保证金,因为它创造了一个整齐的职位之间的差距。
Im wondering does someone have a solution to this? Possibly an easier one that simply stops the margin from happening when its the third one? I need the margin on the other two as it creates a neat gap between the posts.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$archive_query = new WP_Query('cat=14&showposts=14&paged=' . $paged);
$id = get_the_ID();
while ($archive_query->have_posts()) : $archive_query->the_post(); ?>
<div class="events">
<div class="gallerypic"><div class="limerickguideblockheader"><p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?>
</div>
<div class="gallerypiccontainer"><a href="<?php the_permalink(); ?>" >
<?php echo get_the_post_thumbnail( $id, 'gallery-thumb', $attr ); ?> </a></div>
</div>
</div>
<?php endwhile; ?>
编辑:一张图片描绘了一个1000字,这里是目前为止的链接,有三个帖子.. 。
http://limerickfc.hailstormcommerce.com/cms/?page_id=2466
edit: a picture paints a 1000 words, here is the link so far, with three posts... http://limerickfc.hailstormcommerce.com/cms/?page_id=2466
如果可能,通过CSS的方法会更好。
干杯
阿德里安
A method via CSS would be even better if possible. Cheers Adrian
推荐答案
请尝试下面的代码。
<style>
.gallerypicright {
margin: 0;
}
</style>
...
<?php
$count = 0;
while ($archive_query->have_posts()) : $archive_query->the_post();
$count++;
$third_div = ($count%3 == 0) ? 'gallerypicright' : '';
?>
...
<div class="gallerypic <?php echo $third_div; ?>">
这篇关于wordpress循环,每三分之一应用一些新内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!