【发布时间】:2017-03-24 01:34:39
【问题描述】:
我正在使用 while 循环从我的数据库中获取值,结果如下:
我想在循环的最后一个值之后删除逗号。
我使用了类似的代码..
<?php
$cat = get_terms('car_category'); // you can put your custom taxonomy name as place of category.
foreach ($cat as $catVal) {
echo '<b>'.$catVal->name.'</b>';
$postArg = array('post_type'=>'cars','posts_per_page'=>5,'order'=>'desc',
'tax_query' => array(
array(
'taxonomy' => 'car_category',
'field' => 'term_id',
'terms' => $catVal->term_id
)
));
$getPost = new wp_query($postArg);
global $post;
if($getPost->have_posts()){
$str = "";
echo '<div class="yearDiv">';
while ( $getPost->have_posts()):$getPost->the_post();
$str =rtrim($post->post_title, ",");
echo '<span>'.$str.',</span>';
endwhile;
echo '</div>';
}
}
?>
我也使用了 rtrim , substr 函数,但逗号没有删除。
【问题讨论】: