2016-11-12 177 views
0

我想添加一個額外的類到wordpress的自定義帖子的第一篇文章,我在我的模板部分使用下面的代碼,我從sof站點獲得但它顯示錯誤。如何添加類到第一個wordpress的自定義帖子

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(); 
    ?> 

有什麼不對這個代碼?

回答

0

你忘了寫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(); 
?> 
+0

@SBiswas高興聽到之前關閉PHP!歡迎您,愉快的編碼 – caramba

相關問題