prefix . "terms_hit"; if($wpdb->get_var("show tables like '$table_name'") != $table_name) { $sql = "CREATE TABLE $table_name ( term_id bigint(20) NOT NULL, hit bigint(20) DEFAULT 0 NOT NULL, UNIQUE KEY id(term_id) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); add_option("sj_tag_db_version", $jal_db_version); } } register_activation_hook(__FILE__,'sjInstall'); class SJ_Widget_TagCloud extends WP_Widget { public $widget_id = 'tag_cloud_widget_sujin'; public $widget_name; public $widget_title; function __construct() { $this->widget_id = 'tag_cloud_widget_sujin'; $this->widget_name = '2D Tag Cloud Widget by Sujin'; $this->widget_title = '2D Tag Cloud Widget by Sujin'; $widget_ops = array( 'classname' => $this->widget_id, 'description' =>'Generate 2-Dimentional Tag Cloud' ); $control_ops = array( 'width' => 500, ); parent::__construct($this->widget_id, $this->widget_name, $widget_ops, $control_ops); $this->alt_option_name = 'widget_'.$this->id_base; } function widget($args, $instance) { global $wpdb; extract($args, EXTR_SKIP); $number = isset($instance['number']) ? $instance['number'] : 20; $title = isset($instance['title']) ? $instance['title'] : ''; $separator = isset($instance['separator']) ? $instance['separator'] : ''; echo $before_widget; echo $before_title . apply_filters('widget_title', $title) . $after_title; $tag_config = get_option('sj_tag_conifg'); # initialize;; if (!$tag_config) { $tag_step = 1; $tag_config = array( 'color' => array( 1 => array( 'color' => '#000000', 'bgcolor' => '', 'radius' => 0, 'padding' => 0 ) ), 'size' => array( 1 => 12 ) ); $tag_method = 'click-color'; } else { $tag_step = $tag_config['tag_step']; $tag_method = $tag_config['tag_method']; $tag_config = $tag_config['tag_config']; } foreach($tag_config['color'] as &$color) { if(!$color['bgcolor']) $color['bgcolor'] = 'transparent'; $padding2 = $color['padding'] + 2; if ($color['padding']) $color['padding'] = $color['padding'] . 'px ' . $padding2 . 'px'; } $query_count = ' SELECT terms.term_id as term_id, terms.name as tag_name, taxonomy.count as post_count, count.hit as post_hit FROM ' . $wpdb->term_taxonomy . ' as taxonomy LEFT JOIN ' . $wpdb->terms . ' as terms ON taxonomy.term_id = terms.term_id LEFT JOIN ' . $wpdb->term_relationships . ' as relationship ON terms.term_id = relationship.term_taxonomy_id LEFT JOIN ' . $wpdb->posts . ' as post ON post.ID = relationship.object_ID LEFT JOIN ' . $wpdb->prefix . 'terms_hit as count ON count.term_id = terms.term_id WHERE taxonomy.taxonomy = "post_tag" AND count <> 0 GROUP BY terms.term_id ORDER BY post_count DESC LIMIT ' . $number . ' '; $tags_count = $wpdb->get_results($query_count); // 포함수 $query_hit = ' SELECT terms.term_id as term_id, terms.name as tag_name, taxonomy.count as post_count, count.hit as post_hit FROM ' . $wpdb->term_taxonomy . ' as taxonomy LEFT JOIN ' . $wpdb->terms . ' as terms ON taxonomy.term_id = terms.term_id LEFT JOIN ' . $wpdb->term_relationships . ' as relationship ON terms.term_id = relationship.term_taxonomy_id LEFT JOIN ' . $wpdb->posts . ' as post ON post.ID = relationship.object_ID LEFT JOIN ' . $wpdb->prefix . 'terms_hit as count ON count.term_id = terms.term_id WHERE taxonomy.taxonomy = "post_tag" AND count <> 0 GROUP BY terms.term_id ORDER BY post_hit DESC LIMIT ' . $number . ' '; $tags_hit = $wpdb->get_results($query_hit); // 히트수 $tags = array(); // 히트와 뷰를 한 개씩 섞는다 $k = 0; for ($i=0; $i<$number; $i++) { if (isset($tags_count[$i])) { $tags[$tags_count[$i]->term_id] = $tags_count[$i]; if (!isset($tags[$tags_count[$i]->term_id])) { $k++; if ($k == $number) break; } } if (isset($tags_hit[$i])) { $tags[$tags_hit[$i]->term_id] = $tags_hit[$i]; if (!isset($tags[$tags_hit[$i]->term_id])) { $k++; if ($k == $number) break; } } } # 한 자리에 몰아넣는 배열을 만든다, 민/맥스도 뽑고 각각의 녀석에게 스타일도 부여하기 위해 $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) / $tag_step; # 두바퀴만 더 돌려 카운트와 히트를 스텝에 맞는 값으로 변환한다 $i = 0; $prev_value = -1; $prev_chanded = -1; foreach ($count as $key => &$value) { if ($prev_value == $value) { $value = $prev_value; } 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_value; } else { $prev_value = $value; $value = $prev_chanded = floor($i / $tag_step) + 1; // 0,1,2 대신 1,2,3을 사용했으니 편의상 +1 } $i++; } # 준비는 끝났다 +_+ 이제 녀석들을 만들어보자 foreach ($tags as $tag) { $link = get_tag_link($tag->term_id); if ($tag_method == 'click-color') { $tag_size = $count[$tag->term_id]; $tag_color = $hit[$tag->term_id]; } else { $tag_color = $count[$tag->term_id]; $tag_size = $hit[$tag->term_id]; } $style = 'color:' . $tag_config['color'][$tag_color]['color'] . ';'; $style.= 'background-color:' . $tag_config['color'][$tag_color]['bgcolor'] . ';'; $style.= 'border-radius:' . $tag_config['color'][$tag_color]['radius'] . 'px;'; $style.= 'padding:' . $tag_config['color'][$tag_color]['padding'] . ';'; $style.= 'font-size:' . $tag_config['size'][$tag_size] . 'px;'; $style.= 'margin:0 5px 10px 0; display:inline-block; line-height:1.3em; text-decoration:none;'; $tags_out[] = '' . $tag->tag_name . ''; } echo '
' . implode($separator, $tags_out) . '
'; echo $after_widget; } // function widget($args, $instance) function update($new_instance, $old_instance) { $instance = $old_instance; $instance['number'] = $new_instance['number']; $instance['title'] = $new_instance['title']; $instance['separator'] = $new_instance['separator']; return $instance; } // function update($new_instance, $old_instance) function form($instance) { $number = isset($instance['number']) ? $instance['number'] : 20; $title = isset($instance['title']) ? $instance['title'] : ''; $separator = isset($instance['separator']) ? $instance['separator'] : ''; ?>

prefix . "terms_hit"; $tags = get_the_tags(); // for another post type if (!$tags) { $tags = get_the_terms($wp_query->query_vars['p'], 'post_tag'); } if ($tags) { foreach($tags as $tag) { if ($hit = $wpdb->get_var("SELECT hit FROM $table_name WHERE term_id = $tag->term_id")) { $hit++; $wpdb->update($table_name, array('hit' => $hit), array('term_id' => $tag->term_id)); } else { $wpdb->insert($table_name, array('term_id' => $tag->term_id, 'hit' => 1)); } } } } if (is_tag() && $query->is_main_query()) { global $wpdb; $table_name = $wpdb->prefix . "terms_hit"; $term = get_queried_object(); if (!$term) return; if ($hit = $wpdb->get_var("SELECT hit FROM $table_name WHERE term_id = $term->term_id")) { $hit++; $wpdb->update($table_name, array('hit' => $hit), array('term_id' => $term->term_id)); } else { $wpdb->insert($table_name, array('term_id' => $term->term_id, 'hit' => 1)); } } } add_action('parse_query', 'sjCountTagView'); # Admin Page function sj2DTagAddSettingPage() { add_options_page('2D Tag Cloud', '2D Tag Cloud', 'manage_options', '2D-tag-cloud-options', 'sj2DTagSetting'); } function sj2DTagSetting() { if ($_POST['submit'] == 'Save Changes') { $tag_step = $_POST['tag_step']; $tag_method = $_POST['tag_method']; $tag_config = array(); for($i = 1; $i < $_POST['tag_step']+1; $i++) { $tag_config['color'][$i] = array( 'color' => $_POST['tag_color_step_' . $i], 'bgcolor' => $_POST['tag_bgcolor_step_' . $i], 'radius' => $_POST['tag_radius_step_' . $i], 'padding' => $_POST['tag_padding_step_' . $i] ); $tag_config['size'][$i] =$_POST['tag_size_step_' . $i]; } $tag_config = array( 'tag_step' => $tag_step, 'tag_method' => $tag_method, 'tag_config' => $tag_config, ); update_option('sj_tag_conifg', $tag_config); } wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-widget'); wp_enqueue_script('jquery-ui-button'); wp_enqueue_script('jquery-ui-spinner'); wp_enqueue_style('jquery-ui'); wp_enqueue_script('iris'); wp_enqueue_script('sujin_tag', plugin_dir_url( __FILE__ ) . '/assets/admin.js'); wp_enqueue_style('sujin_tag', plugin_dir_url( __FILE__ ) . '/assets/admin.css'); $tag_config = get_option('sj_tag_conifg'); # initialize;; if (!$tag_config) { $tag_step = 1; $tag_config = array( 'color' => array( 1 => array( 'color' => '#000000', 'bgcolor' => '', 'radius' => 0, 'padding' => 0 ) ), 'size' => array( 1 => 12 ) ); $tag_method = 'click-color'; } else { $tag_step = $tag_config['tag_step']; $tag_method = $tag_config['tag_method']; $tag_config = $tag_config['tag_config']; } ?>

2D Tag Cloud

General

Color

    $value) { ?>
  • Step

Size

    $value) { ?>
  • Step

Cancel