如何添加类到第一个wordpress的自定义帖子
问题描述:
我想添加一个额外的类到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();
?>
有什么不对这个代码?
答
你忘了写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();
?>
@SBiswas高兴听到之前关闭
PHP
!欢迎您,愉快的编码 – caramba