joshuap
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: Limit tags by dateI just wrote this to display a tag cloud of all tags used within a certain date range of posts. It seems to be working correctly but I’m afraid it may be a resource hog – can you guys test it out and verify that the query is constructed correctly? Is there a way to do it better?
<?php // Set up the query $now = gmdate("Y-m-d H:i:s",time()); $datelimit = gmdate("Y-m-d H:i:s",gmmktime(date("H"), date("i"), date("s"), date("m")-1,date("d"),date("Y"))); $popterms = "SELECT $wpdb->terms.*, COUNT($wpdb->terms.term_id) as count FROM $wpdb->posts, $wpdb->term_relationships, $wpdb->term_taxonomy, $wpdb->terms WHERE $wpdb->posts.ID=$wpdb->term_relationships.object_id AND $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id AND $wpdb->term_taxonomy.term_id=$wpdb->terms.term_id AND post_status = 'publish' AND post_date < '$now' AND post_date > '$datelimit' AND $wpdb->term_taxonomy.taxonomy='post_tag' GROUP BY $wpdb->terms.term_id ORDER BY post_date DESC"; $terms = $wpdb->get_results($popterms); if($terms){ // Arguments for wp_generate_tag_cloud // See wp_tag_cloud (line 560): https://core.trac.www.ads-software.com/browser/trunk/wp-includes/category-template.php $args = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true ); // Create links foreach ( $terms as $key => $tag ) { if ( 'edit' == $args['link'] ) $link = get_edit_tag_link( $tag->term_id, $args['taxonomy'] ); else $link = get_term_link( intval($tag->term_id), $args['taxonomy'] ); if ( is_wp_error( $link ) ) return false; $terms[ $key ]->link = $link; $terms[ $key ]->id = $tag->term_id; } // Generate cloud echo wp_generate_tag_cloud( $terms, $args ); } ?>
Viewing 1 replies (of 1 total)