【发布时间】:2017-05-06 10:05:14
【问题描述】:
我想这肯定是一个新手问题,但我尝试修改在其他问题上找到的一些代码,但我仍然无法找到如何循环浏览帖子的类别并使它们显示为 Bootstrap 4 徽章。
if ( ! function_exists( 'mytheme_the_categories' ) ) :
/**
* Prints HTML with the categories, formatted as Bootstrap 4 badges.
*/
function mytheme_the_categories() {
$categories_list = get_the_category_list();
if ( $categories_list && positor_categorized_blog() ) {
echo '<div class="entry-categories"><span class="sr-only">'. esc_html__( 'Posted in ', 'positor' ) . '</span>';
foreach ($categories_list as $category) {
echo '<span class="badge badge-primary">';
echo $category->name;
echo '</span>';
}
echo '</div>';
}
}
endif;
但是得到一个错误:“警告:为 foreach() 提供的参数无效”
【问题讨论】: