将数组输出分离到<ul> 时间:2016-10-28 作者:Aaron Bradford 我有一段PHP代码,它查看了每篇文章,并显示了它在归档页面上列出的类别,但我想用逗号或空格来分隔它们。谢谢 <?php if ( ! $jobs ) : ?> <tr> <td colspan="6"><?php _e( \'You do not have any active listings.\', \'wp-job-manager\' ); ?></td> </tr> <?php else : ?> <?php foreach ( $jobs as $job ) : ?> <tr> <?php foreach ( $job_dashboard_columns as $key => $column ) : ?> <td class="<?php echo esc_attr( $key ); ?>"> <?php if (\'job_title\' === $key ) : ?> <?php if ( $job->post_status == \'publish\' ) : ?> <a href="<?php echo get_permalink( $job->ID ); ?>"><?php echo $job->post_title; ?></a><br> Job Status: <?php $terms = wp_get_post_terms( $job->ID, \'job_listing_category\' ); foreach ( $terms as $term ) { echo $term->name; } ?> <?php else : ?> <?php echo $job->post_title; ?> <small> (<?php the_job_status( $job ); ?>)</small> <?php endif; ?> 1 个回复 最合适的回答,由SO网友:cowgill 整理而成 这个foreach 不需要循环。这将列出用逗号分隔的所有工作类别。$terms = wp_get_post_terms( $job->ID, \'job_listing_category\' ); echo implode( \', \', wp_list_pluck( $terms, \'name\' ) ); // Marketing, Sales, Finance, Support 文章导航