使用Enhanced Media Library 插件中,我添加了自定义媒体类别,现在正尝试将这些类别作为类应用于[库]快捷代码中显示的图像。这是我正在使用的代码(在自定义[库]快捷码中):
$terms = get_terms(\'media_category\', array(\'parent\' => \'15\'));
foreach ( $terms as $id => $term ) {
$term = $term->slug;
}
这段代码将类别名称作为类输出,但是它仅将库中第一幅图像的类别应用于其他每幅图像,而忽略其他图像的类别。因为我已经注册Isotope, 我还使用媒体类别对库进行排序。此代码工作正常:
$terms = get_terms(\'media_category\', array(\'parent\' => \'15\'));
$count = count($terms);
if ( $count > 0 ){
foreach ( $terms as $term ) {
echo "<button type=\'button\' class=\'btn\' data-hover=\'" . $term->name . "\' data-filter=\'." . $term->slug . "\'>" . $term->name . "</button>\\n";
}
}
我在第一段代码中遗漏了什么?