WordPress的 - 从一个类别获取图像
问题描述:
即时通讯使用分类图像插件,它允许我分配图像的类别...即时通讯不太确定如何在前端显示它。WordPress的 - 从一个类别获取图像
我的代码显示的类别如下:
$cat = get_query_var('cat');
$args = array(
'orderby' => 'id',
'child_of' => $cat,
'hide_empty' => 0
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<a href="' . get_category_link($category->term_id) . '" class="cat-c-top-bg">' . "\n";
echo ' <h4>' . $category->name . '</h4>' . "\n";
echo ' <div class="icon-view">' . "\n";
echo ' </div>' . "\n";
echo ' <div>' . "\n";
echo ' <img src="" width="164" height="164"></img>' . "\n";
echo ' </div>' . "\n";
echo ' <div class="cat-bot-ext_bg">' . "\n";
echo ' </div>' . "\n";
echo '</a>' . "\n";
}
其中一期工程完美...虽然,磨片我输入的图像插件提供的代码,它显示的图像多次有类别,这是代码即时放在里面的foreach声明
$terms = apply_filters('taxonomy-images-get-terms', '');
if (! empty($terms)) {
print '<ul>';
foreach((array) $terms as $term) {
print '<li><a href="' . esc_url(get_term_link($term, $term->taxonomy)) . '">' . wp_get_attachment_image($term->image_id, 'detail') . '</li>';
}
print '</ul>';
}
任何帮助,这将是伟大的。
干杯,
答
声明
$terms = apply_filters('taxonomy-images-get-terms', '')
是get_terms或get_categories的替代品。所以你应该这样做
$terms = apply_filters('taxonomy-images-get-terms', '')
foreach((array) $terms as $term) {
print wp_get_attachment_image($term->image_id, 'thumbnail');
echo ' <h4>' . $term->name . '</h4>' . "\n";
//everything you wanna print
}