我在Wordpress中生成一个自定义帖子类型的术语列表,在这个代码中我添加一个逗号到每个项目的末尾以列表格式分隔它,我将如何消除最后一个逗号在传播时添加或删除列表中的最后一个逗号.
$terms = get_the_terms( $post->ID, 'clients' );
if ( $terms && ! is_wp_error( $terms ) ) :
$clients_list = array();
foreach ( $terms as $term ) {
$clients_list[] = $term->name;
}
$clients = join( ", ", $clients_list );
$catTags .= "$clients, ";
endif;
Run Code Online (Sandbox Code Playgroud)
我试过以下没有成功;
<em><?php $string = $catTags;
echo preg_replace("/\,$/","",$catTags); ?></em>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3099 次 |
| 最近记录: |