Skip to content

Instantly share code, notes, and snippets.

@tollmanz
Created May 3, 2012 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tollmanz/2590362 to your computer and use it in GitHub Desktop.
Save tollmanz/2590362 to your computer and use it in GitHub Desktop.
A Skeleton
<?php
class MostDiscussed_Widget extends WP_Widget {
private $excluded_posts;
function __construct() {
}
function widget( $args, $instance ) {
$excluded_posts = get_transient( 'consumerist_most_discussed_exclude' );
if ( false === $excluded_posts )
$excluded_posts = $this->generate_most_discussed_excluded_posts();
$pop_query = get_transient( 'consumerist_most_discussed_exclude' );
if ( false === $pop_query )
$pop_query = $this->generate_most_discussed_query();
// Get your loop on
}
function update( $new_instance, $old_instance ) {
// Do the normal validation
$this->generate_most_discussed_excluded_posts();
$this->generate_most_discussed_query();
return $instance;
}
function form( $instance ) {
}
function generate_most_discussed_excluded_posts() {
// Query for the excluded posts and save to transient
$excluded_posts = wp_list_pluck( $excluded_posts->posts, 'ID' );
set_transient( 'consumerist_most_discussed_exclude', $excluded_posts ); // no expiration
$this->excluded_posts = $excluded_posts;
return $excluded_posts;
}
function generate_most_discussed_query() {
// Query for most discussed posts and save to transient
set_transient( 'consumerist_most_discussed', $pop_query ); // no expiration
return $pop_query;
}
function filter_most_discussed( $where = '' ) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment