我正在尝试在wordpress的自定义帖子的第一篇文章中添加一个额外的类,我在我的模板部分使用以下代码,我从sof site获得但是它显示错误。
解析错误:语法错误,意外'<'在 在线:C:\ xampp \ htdocs \ e24xp \ wp-content \ themes \ e24x \ testimonial.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();
?>
这段代码有什么问题?
答案 0 :(得分:0)
在撰写PHP
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();
?>