douhu2890
douhu2890
2015-09-14 07:51

drupal 7类别和计数列表

已采纳

Making my code but, not what I want

$query = db_select('field_data_field_job','f');
$query->distinct('field_job');
$query->fields('f',array('field_job_value'));
$query->isNotNull('field_job_value');
$query->orderBy('field_job_value', 'ASC');
$items = $query->execute()->fetchAll();
$node = node_load($node->nid);
$field = field_info_field('field_job');
echo '<ul class="chapter-list">';
foreach($items as $key=>$value) {
$item = $value->field_job_value;
$label = $field['settings']['allowed_values'][$item];
$labels = $field['settings']['allowed_values'][$item];
echo '<li class=""><a href="'.$base_url.'/jobs/'.$item.'">'.$label.' '.$labels.'</a></li>';
}
echo '</ul>';

list of construction workers

  Nurse 
  Doctor

I want to be, category list.

Nurse (5)
Doctor (4)
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dsykx64220 dsykx64220 6年前

    completed :)

    foreach($items as $key=>$value) {
    $item = $value->field_job_value;
    $label = $field['settings']['allowed_values'][$item];
    $queryItem = db_select('field_data_field_job','f');
    $queryItem->fields('f',array('field_job_value'));
    $queryItem->isNotNull('field_job_value');
    $queryItem->condition('field_job_value', $item, '=');
    $count_query = $queryItem->countQuery()->execute()->fetchField();
    
    echo '<li class=""><a href="'.$base_url.'/jobs/'.$item.'">'.$label.' ('.$count_query.') </a></li>';
    }
    echo '</ul>';
    
    点赞 评论 复制链接分享

为你推荐