douxie5176 2013-11-06 06:06
浏览 7
已采纳

如何在第一篇文章中添加课程?

Here my code, now i want add "active" class in first post. Some Please help me solve this. i used $i for adding new class.

<?php         
    $args = array( 'post_type' => 'cc_testimonial', 'posts_per_page' => 1, "order" => "DESC");
    $query = new WP_Query( $args );
    $cc = count($query);
    if ( $query->have_posts() ) {
    while ( $query->have_posts() ) { 
    $query->the_post();
?>
<?php for($i = 0; $i<$cc; $i++){ ?>
                    <div class="testimonialitem item <?php echo ($i==0)?'active':'' ?>">
                        <div class="testimonial-content">
                            <p><?php the_title( );?></p>
                        </div>                          
                    </div><!--/.testimonialitem-->                      


<?php    
}
            }
        }
        wp_reset_query();
        wp_reset_postdata();
?>
  • 写回答

3条回答 默认 最新

  • dream0614 2013-11-06 06:47
    关注

    For applying active class to your FIRST post , try below code:

    <?php         
    $args = array( 'post_type' => 'cc_testimonial', 'posts_per_page' => 1, "order" => "DESC");
    $query = new WP_Query( $args );
    $cc = count($query);
    if ( $query->have_posts() ) {
    $i=0;
    while ( $query->have_posts() ) { 
    $query->the_post();
    <div class="testimonialitem item <?php echo ($i==0)?'active':''; ?>">
                        <div class="testimonial-content">
                            <p><?php the_title( );?></p>
                        </div>                          
                    </div><!--/.testimonialitem-->       
          $i++; 
           }
        }
        wp_reset_query();
        wp_reset_postdata();
       ?>
    

    Thanks.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 touchsocket udp组播
  • ¥20 MAC怎么安装Silverlight 插件?以及安装了怎么启用
  • ¥15 VS2012中查询语句无法填入解析,数值传不进去
  • ¥15 gis系统开发出现命名空间“ESRI.ArcGIS”中不存在类型或命名空间名“Analyst3D”报错
  • ¥15 怎么让ai定时给我发信息 c#或者python
  • ¥15 scrapy的Error
  • ¥15 RBF-VSG姚凤军论文复现问题
  • ¥30 开发一个APP商城在制作tabbar的时候运行不了代码没有检查出错误,但是显示不出tabbar,以下为运行结果,如何解决?
  • ¥15 多网卡服务器中winform如何绑定指定网卡
  • ¥15 关于#python#pandas#的问题,想要实现:多个TXT导入Excel,进行分列,不同txt之间都从第一行开始,请各位专家解答!