* * Copyright 2008-2011 Crowd Favorite, Ltd. All rights reserved. * Released under the GPL license * http://www.opensource.org/licenses/gpl-license.php * * This file contains function wrappers for a few custom additions to the standard WordPress * template tag milieu. */ if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) { die(); } class Anno_Widget_Recently extends WP_Widget { public $key = 'anno_recently_html'; public $timeout = 3600; // 1 hour public $enable_cache = true; public $html_uid; public $number = 5; protected static $script_initiated = false; public function __construct() { $args = array( 'description' => __('Display the most recent posts and comments in a tabbed box.', 'anno'), 'classname' => 'widget-recent-posts' ); parent::__construct('anno_recently', __('Recently…'), $args); $this->html_uid = uniqid('anno-recently'); // Clear widget cache on one of these important events add_action( 'save_post', array($this, 'flush_widget_cache') ); add_action( 'deleted_post', array($this, 'flush_widget_cache') ); add_action( 'switch_theme', array($this, 'flush_widget_cache') ); add_action( 'comment_post', array($this, 'flush_widget_cache') ); add_action( 'transition_comment_status', array($this, 'flush_widget_cache') ); } public function widget($args, $instance) { $before_widget = null; $after_widget = null; extract($args); $cache = get_transient($this->key); if ($cache === false || $this->enable_cache === false) { ob_start(); $this->cached($args, $instance); $cache = ob_get_clean(); set_transient($this->key, $cache, $this->timeout); } echo $before_widget; echo $cache; echo $after_widget; } public function cached($args, $instance) { ?>
'article', 'posts_per_page' => $this->number )); if ($articles->have_posts()) { echo '
    '; while ($articles->have_posts()) { $articles->the_post(); ?>
  1. '; wp_reset_postdata(); unset($articles); } ?>
$this->number, 'status' => 'approve', 'post_status' => 'publish' )); if (is_countable( $comments ) && count($comments)) { echo '
key); } } ?>