【发布时间】:2014-10-22 03:20:18
【问题描述】:
我正在开发一个自定义主题,并且在其中一个页面上我需要将帖子页面设置为如下样式:http://gyazo.com/e1f7cfc03c7ba3981188077afcdf0314
灰色框是图片,红色框是内容。我可能需要使用奇/偶 Li/Ul 伪类/选择器,但我不知道该怎么做。
谁能给我一个启动它的方法?我正在考虑使用 UL 上的 Odd/Even 伪类来更改 div 名称,但是我不知道该怎么做或从哪里开始。
谢谢!
编辑:我在想奇数/偶数选择器与 jquery prepend/append 结合使用?
Edit2:这是我所拥有的,但它首先显示所有赔率,然后显示所有偶数,而不是交替显示。
PHP:
<?php $i++; if(($i % 2) == 0) : $wp_query->next_post(); else : the_post(); ?>
<div class="section group">
<div class="col span_1_of_2 blue doubleheight">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large'); ?></a>
</div>
<div class="col span_1_of_3_30 blue doubleheight">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="post-text"><?php the_excerpt(); ?></div>
</div>
</div>
<?php echo $i; ?>
<?php endif; endwhile; ?>
<?php while(have_posts()) : ?>
<?php $i++; if(($i % 2) !== 0) : $wp_query->next_post(); else : the_post(); ?>
<div class="section group">
<div class="col span_1_of_3_30 blue doubleheight">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="post-text"><?php the_excerpt(); ?></div></div>
<div class="col span_1_of_2 blue doubleheight">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large'); ?></a>
</div>
</div>
<?php echo $i; ?>
<?php endif; endwhile; ?>
【问题讨论】:
-
是的,我已经在原始帖子中发布了我的代码,谢谢
-
如果你有一个你需要的布局(例如左边的图像,右边的文本),并且只是重复,你可以使用
:nth-child(2n)pseudoselector,并使用css使图像浮动(或绝对定位它们)在另一侧。这样一来,其他所有元素都将具有该定位。 -
问题是,我使用 Div 作为图像,使用 Div 作为信息,所以我不确定这是否可行?
-
如果它们每次都在具有相同类的包装器中,那么只需定位该包装器。像这样jsfiddle.net/gq5veb9L
-
这很好用,非常干净,谢谢。
标签: php jquery css wordpress html-lists