首页 > 解决方案 > 显示分类并使用已分配帖子的缩略图

问题描述

我有一个分层分类法,例如:

在子术语页面上,我想用缩略图列出兄弟姐妹。开箱即用的分类法不支持缩略图,因此我想获取分配给该术语的自定义帖子之一的缩略图。使这成为可能的最佳方法是什么?


$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(  );
      //

    }
  }
}

标签: phpwordpresscustom-post-typetaxonomy-terms

解决方案


推荐阅读