+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term ) );
+ $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
+ }
+}
+
+/**
+ * get_term_link() - Generates a permalink for a taxonomy term archive
+ *
+ * @param object|int|string $term
+ * @param string $taxonomy
+ * @return string HTML link to taxonomy term archive
+ */
+function get_term_link( $term, $taxonomy ) {
+ global $wp_rewrite;
+
+ // use legacy functions for core taxonomies until they are fully plugged in
+ if ( $taxonomy == 'category' )
+ return get_category_link($term);
+ if ( $taxonomy == 'post_tag' )
+ return get_tag_link($term);
+
+ $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
+
+ if ( !is_object($term) ) {
+ if ( is_int($term) ) {
+ $term = &get_term($term, $taxonomy);
+ } else {
+ $term = &get_term_by('slug', $term, $taxonomy);
+ }
+ }
+ if ( is_wp_error( $term ) )
+ return $term;
+
+ $slug = $term->slug;
+
+ if ( empty($termlink) ) {
+ $file = get_option('home') . '/';
+ $t = get_taxonomy($taxonomy);
+ if ( $t->query_var )
+ $termlink = "$file?$t->query_var=$slug";
+ else
+ $termlink = "$file?taxonomy=$taxonomy&term=$slug";
+ } else {
+ $termlink = str_replace("%$taxonomy%", $slug, $termlink);
+ $termlink = get_option('home') . user_trailingslashit($termlink, 'category');
+ }
+ return apply_filters('term_link', $termlink, $term, $taxonomy);
+}
+
+function the_taxonomies($args = array()) {
+ $defaults = array(
+ 'post' => 0,
+ 'before' => '',
+ 'sep' => ' ',
+ 'after' => '',
+ );
+
+ $r = wp_parse_args( $args, $defaults );
+ extract( $r, EXTR_SKIP );
+
+ echo $before . join($sep, get_the_taxonomies($post)) . $after;
+}
+
+function get_the_taxonomies($post = 0) {
+ if ( is_int($post) )
+ $post =& get_post($post);
+ elseif ( !is_object($post) )
+ $post =& $GLOBALS['post'];
+
+ $taxonomies = array();
+
+ if ( !$post )
+ return $taxonomies;
+
+ $template = apply_filters('taxonomy_template', '%s: %l.');
+
+ foreach ( get_object_taxonomies($post) as $taxonomy ) {
+ $t = (array) get_taxonomy($taxonomy);
+ if ( empty($t['label']) )
+ $t['label'] = $taxonomy;
+ if ( empty($t['args']) )
+ $t['args'] = array();
+ if ( empty($t['template']) )
+ $t['template'] = $template;
+
+ $terms = get_object_term_cache($post->ID, $taxonomy);
+ if ( empty($terms) )
+ $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
+
+ $links = array();
+
+ foreach ( $terms as $term )
+ $links[] = "<a href='" . attribute_escape(get_term_link($term, $taxonomy)) . "'>$term->name</a>";
+
+ if ( $links )
+ $taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms);