怎样针对图片引入不同的class?

2012-02-29 14:29:32 +08:00
 joynic
使用wordpress,想实现首页以图片墙的形式展示文章。每篇文章仅显示一张缩略图。三张图片为一行(即三篇文章)。请问怎样针对这三张图片引入不同的class?

比如:

<li id="post-<?php the_ID(); ?>" class="group">图片A</li>
<li id="post-<?php the_ID(); ?>" class="group">图片B</li>
<li id="post-<?php the_ID(); ?>" class="group third">图片C</li>

问题很菜。
3518 次点击
所在节点    问与答
8 条回复
joynic
2012-02-29 21:12:04 +08:00
^_^有人能帮忙一下吗?
sobigfish
2012-02-29 21:27:09 +08:00
id索引index index%3
icyflash
2012-02-29 21:32:23 +08:00
你这样做是为了解决什么问题呢?

如果是要每行的最后一个添加一个固定的class的话,添加一个变量i,i/3==0?' third':''
joynic
2012-02-29 21:52:26 +08:00
@icyflash
恩,就是实现每行的最后那张图的class多增加一个third

效果参考http://dribbble.com/

SORRY,我也没说清楚。

具体应该怎么写呢?谢谢^_^
icyflash
2012-02-29 22:21:20 +08:00
<?php
if ( have_posts() ):
$i=0;
while ( have_posts() ) :the_post();
$i++; ?>
<li id="post-<?php the_ID(); ?>" class="group <?php echo($i/3==0?' third':'') ?>">图片A</li>
<?php endwhile; // end of the loop. ?>
<?php endif; ?>
php和WP我都不熟悉,你自己在试试
sobigfish
2012-02-29 22:23:19 +08:00
@icyflash 从3楼 我就想说。大哥取余是 %
icyflash
2012-02-29 22:42:39 +08:00
@sobigfish 呃,我弄错了
joynic
2012-02-29 22:57:23 +08:00
@sobigfish @icyflash 谢谢两位,搞定了^_^

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/28413

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX