duanlan4801 2016-11-12 07:19
浏览 36
已采纳

如何将类添加到第一个wordpress自定义帖子[重复]

This question already has an answer here:

I am trying to add an additional class to the very first post of a custom post in wordpress and I am using the following code on my template part that I got from sof site but it is showing an error.

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\e24xp\wp-content\themes\e24x\testimonial.php on line 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();
   ?>

What is wrong in this code??

</div>
  • 写回答

1条回答 默认 最新

  • doucuo4413 2016-11-12 07:32
    关注

    You forgot to close PHP before writing HTML

    <?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();
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教