【发布时间】:2019-03-17 20:17:12
【问题描述】:
我在 WP 循环中有以下代码
<?php
// Get the selected taxonomies for the post type
$terms = get_the_terms( get_the_ID(), 'course_type' );
$classes = array();
if ( $terms && ! is_wp_error( $terms ) ){
foreach ( $terms as $term) {
$classes[] = $term->slug;
}
}
?>
我要做的是只打印 WP_Term 对象 slug 以在类中使用。
<div class="courses-search-result standout-box-shadow <?php print_r( $classes ); ?>">
现在,我已经让它工作到一定程度并在类中打印一个值 - 但它也在打印数组结构:
class="courses-search-result standout-box-shadow cilex-clearfix Array
(
[0] => apprenticeship
)
"
我是否接近使用我的 PHP 获得正确的代码?我现在对这门语言的了解还很基础,因此我们将不胜感激。
【问题讨论】: