2016-10-01 8 views
1

これは私のコードであり、ループ内の2番目の子にクラスを追加したいと思います。どうすればいいのか教えてください。私はワードプレスで新しいです。どのようにワードプレスループ内の特定の子にクラスを追加する

<?php 
     $args = array(
      'posts_per_page' => 3, 
      'post_type' => 'hosting_plan', 
      'order' => 'ASC' 
     ); 
     query_posts($args); 
     if (have_posts()) : while (have_posts()) : the_post(); 
    ?> 
     <div class="hostplbx /*here i want to add class on second child*/"> 
      <h3><?php the_field('plan_name'); ?></h3> 
      <div class="hostprice"> 
       <span class="hosprice"><b class="rs"><?php the_field('plan_price'); ?></b> per month</span> 
       <span class="plandetail"><?php the_field('tag_line'); ?></span> 
      </div> 

      <?php the_content(); ?> 

      </div> 
      <?php endwhile; ?> 
      <?php endif; ?> 

答えて

0

あなたは、単純なイテレータ変数を使用することができます - あなたのテンプレートに適用するために変更することができますいくつかのサンプルコードを:

$counter = 1; 

if (have_posts()) : while (have_posts()) : the_post(); 

    if($counter == 2) echo "<div class='second_child_class'>content goes here</div>"; 
    else echo "<div>content goes here</div>"; 

    $counter++; 

endwhile; endif; 
関連する問題