joynic
V2EX  ›  问与答

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

  •  
  •   joynic · Feb 29, 2012 · 4154 views
    This topic created in 5189 days ago, the information mentioned may be changed or developed.
    使用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>

    问题很菜。
    8 replies    1970-01-01 08:00:00 +08:00
    joynic
        1
    joynic  
    OP
       Feb 29, 2012
    ^_^有人能帮忙一下吗?
    run2
        2
    run2  
       Feb 29, 2012
    id索引index index%3
    icyflash
        3
    icyflash  
       Feb 29, 2012
    你这样做是为了解决什么问题呢?

    如果是要每行的最后一个添加一个固定的class的话,添加一个变量i,i/3==0?' third':''
    joynic
        4
    joynic  
    OP
       Feb 29, 2012
    @icyflash
    恩,就是实现每行的最后那张图的class多增加一个third

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

    SORRY,我也没说清楚。

    具体应该怎么写呢?谢谢^_^
    icyflash
        5
    icyflash  
       Feb 29, 2012
    <?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我都不熟悉,你自己在试试
    run2
        6
    run2  
       Feb 29, 2012
    @icyflash 从3楼 我就想说。大哥取余是 %
    icyflash
        7
    icyflash  
       Feb 29, 2012
    @sobigfish 呃,我弄错了
    joynic
        8
    joynic  
    OP
       Feb 29, 2012
    @sobigfish @icyflash 谢谢两位,搞定了^_^
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2634 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 15:48 · PVG 23:48 · LAX 08:48 · JFK 11:48
    ♥ Do have faith in what you're doing.