php - 显示分类并使用已分配帖子的缩略图
问题描述
我有一个分层分类法,例如:
- 国家
- 城市
在子术语页面上,我想用缩略图列出兄弟姐妹。开箱即用的分类法不支持缩略图,因此我想获取分配给该术语的自定义帖子之一的缩略图。使这成为可能的最佳方法是什么?
$qobject = get_queried_object();
if(!empty($qobject->term_id)){
// get current term
$thiscat = get_term( get_queried_object() , 'vacations-areas' );
$parent_name = get_term( $thiscat->parent )->name;
// get childs terms
$subcategories = get_terms(array(
'taxonomy' => 'vacations-areas',
'hide_empty' => false,
'exclude' => $thiscat->term_id,
'parent' => get_queried_object_id()
));
// if no childs get siblings
if(empty($subcategories) && $thiscat->parent != 0) {
$subcategories = get_terms(array(
'taxonomy' => 'vacations-areas',
'hide_empty' => false,
'exclude' => $thiscat->term_id,
'parent' => $thiscat->parent
));
}
if(!empty($subcategories)) { ?>
foreach($subcategories as $subcat)
echo $subcat->name;
//
// get the wp_get_attachment_image( );
//
}
}
}
解决方案
推荐阅读
- laravel - 反应原生应用程序返回 404 错误
- listview - 如何使用非附加滚动条来滚动 ListView,其中委托具有不同的高度?
- python - 如何加速非内置函数?如何使用椭圆或圆形内核进行 MaxPool 操作?
- django - Django - 更新内联表单集不更新
- python - Flask - db 'unique' 约束有效,但不返回错误,因此如果使用用户名/电子邮件,我可以向用户闪烁消息。如何通知用户?
- angular - Angular 9 网站未提取更新的 javascript 文件
- java - 无法将图像推送到 Firebase 存储并在应用中显示
- excel - 是否可以在 Excel 中编写公式来查找范围单元格中的子字符串并返回找到的单元格的值?
- css - CSS 覆盖或继承
- python - 尝试在 emacs 中安装 python-pycompile