如何在第一篇wordpress自定义文章中添加类


How to add class to first wordpress custom post

我正在尝试添加一个额外的类到wordpress的自定义帖子的第一篇文章,我使用下面的代码在我的模板部分,我从sofsite得到,但它显示一个错误。

解析错误:语法错误,意外的'<' inC:'xampp'htdocs'e24xp'wp-content'themes'e24x' support .php上线19日

    <?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':''; ?>">//SHOWING ERROR
                    <div class="testimonial-content">
                        <p><?php the_title( );?></p>
                    </div>                          
                </div><!--/.testimonialitem-->       
      $i++; 
       }
    }
    wp_reset_query();
    wp_reset_postdata();
   ?>

这段代码有什么问题??

在写HTML之前忘记关闭PHP

<?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(); 
// need to close PHP here ?>
<div class="testimonialitem item <?php echo ($i==0)?'active':''; ?>"> <!-- this is Html comment SHOWING ERROR -->
                <div class="testimonial-content">
                    <p><?php the_title( );?></p>
                </div>                          
            </div><!--/.testimonialitem-->       
<?php // and open it here again
  $i++; 
   }
}
wp_reset_query();
wp_reset_postdata();
?>