term_id] = $tags_count[$i]; if (!isset($tags[$tags_count[$i]->term_id])) { $k++; if ( $k == $options['number'] ) break; } } if ( $options['sort'] == 'intersection' ) { $j = $options['number'] - $i; } else { $j = $i; } if (isset($tags_hit[$j])) { $tags[$tags_hit[$j]->term_id] = $tags_hit[$j]; if (!isset($tags[$tags_hit[$j]->term_id])) { $k++; if ($k == $options['number']) break; } } } $tags = array_slice( $tags, 0, $options['number'] ); # 한 자리에 몰아넣는 배열을 만든다, 민/맥스도 뽑고 각각의 녀석에게 스타일도 부여하기 위해 $hit = $count = $tags_out = array(); foreach ($tags as $tag) { $hit[$tag->term_id] = $tag->post_hit; $count[$tag->term_id] = $tag->post_count; } # 값으로 정렬 asort( $count ); asort( $hit ); # 한 단계에 몇 개의 태그가 들어가는지... $tag_step = count( $tags ) / count( $tag_config['tag_config'] ); # 두바퀴만 더 돌려 카운트와 히트를 스텝에 맞는 값으로 변환한다 $i = 0; $prev_value = -1; $prev_chanded = -1; foreach ( $count as $key => &$value ) { if ( $prev_value == $value ) { $value = $prev_chanded; } else { $prev_value = $value; $value = $prev_chanded = floor( $i / $tag_step ) + 1; // 0,1,2 대신 1,2,3을 사용했으니 편의상 +1 } $i++; } $i = 0; $prev_value = -1; $prev_chanded = -1; foreach ( $hit as $key => &$value ) { if ( $prev_value == $value ) { $value = $prev_chanded; } else { $prev_value = $value; $value = $prev_chanded = floor( $i / $tag_step ) + 1; // 0,1,2 대신 1,2,3을 사용했으니 편의상 +1 } $i++; } if ( $options['sort'] == 'name' || $options['sort'] == 'alphabetical') { $new_tag = array(); foreach ($tags as $tag) { $new_tag[strtolower( $tag->tag_name )] = $tag; } ksort( $new_tag ); $tags = $new_tag; } # 준비는 끝났다 +_+ 이제 녀석들을 만들어보자 $i = 0; $tags_out = array(); foreach ($tags as $tag) { $link = get_tag_link($tag->term_id); if ($tag_config['tag_method'] == 'click-color') { $tag_size = $count[$tag->term_id]; $tag_color = $hit[$tag->term_id] ? $hit[$tag->term_id] : 1; } else { $tag_color = $count[$tag->term_id]; $tag_size = $hit[$tag->term_id] ? $hit[$tag->term_id] : 1; } $tags_out[] = '' . $tag->tag_name . ''; $i++; } $output = '
'; $output.= implode( $options['separator'], $tags_out); $output.= '
'; $output.= ''; $cache[$set] = $output; update_option( 'SJ_2DTAG_CACHE', $cache ); return $output; } }